From 2fc5e09bd5bcc4337547bfc82135509a68dc1fdf Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Sat, 15 Jun 2024 08:42:55 -0500 Subject: [PATCH] task: allowing to trigger the search with ctrl+k --- internal/assets/doco.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/internal/assets/doco.js b/internal/assets/doco.js index 67e5cff..783703c 100644 --- a/internal/assets/doco.js +++ b/internal/assets/doco.js @@ -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 @@ -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"; } @@ -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(); - } } });