Skip to content

Commit

Permalink
task: allowing to trigger the search with ctrl+k
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni committed Jun 15, 2024
1 parent bc8ceb5 commit 2fc5e09
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions internal/assets/doco.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ let doco = {
document.getElementById("search-input").addEventListener("keyup", (e) => {
doco.search.do(e.target.value)
});

// Up and down navigation.
document.addEventListener("keydown", () => {
let paletteVisible = document
Expand All @@ -85,10 +86,7 @@ let doco = {
}

let selector = "#search-results li.selected";
let quickLinksVisisble = document
.querySelector("#search-quick-actions")
.classList.contains("hidden");

let quickLinksVisisble = document.querySelector("#search-quick-actions").classList.contains("hidden");
if (!quickLinksVisisble) {
selector = "#search-quick-actions li.selected";
}
Expand Down Expand Up @@ -136,17 +134,16 @@ let doco = {

//Esc and CMD+k toggle
document.addEventListener("keydown", (e) => {
if (e.keyCode === 27) {
// Close search on ESC
if (e.code === 'Escape') {
doco.search.hide();
// hide image container
imageContainer.classList.add("hidden");
}

if (e.keyCode >= 65 && e.keyCode <= 90) {
let char = (e.metaKey ? "⌘-" : "") + String.fromCharCode(e.keyCode);
if (char == "⌘-K") {
// CMD+k or CTRL+k
if ((e.key === 'K' || e.key === 'k') && (e.metaKey || e.ctrlKey)) {
doco.search.show();
}
}
});

Expand Down

0 comments on commit 2fc5e09

Please sign in to comment.