From 08c0302e569da4f3ade660df4d8a83fa83cd831b Mon Sep 17 00:00:00 2001 From: Aaron Pham Date: Thu, 29 Aug 2024 16:40:01 -0400 Subject: [PATCH] feat(search): add additional keybinding for navigating search results Add support for ctrl-n and ctrl-p to simulate scrolling similar to vim Signed-off-by: Aaron Pham --- quartz/components/scripts/search.inline.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts index 73e64b361..9852e0885 100644 --- a/quartz/components/scripts/search.inline.ts +++ b/quartz/components/scripts/search.inline.ts @@ -242,7 +242,11 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { await displayPreview(anchor) anchor.click() } - } else if (e.key === "ArrowUp" || (e.shiftKey && e.key === "Tab")) { + } else if ( + e.key === "ArrowUp" || + (e.shiftKey && e.key === "Tab") || + (e.ctrlKey && e.key === "p") + ) { e.preventDefault() if (results?.contains(document.activeElement)) { // If an element in results-container already has focus, focus previous one @@ -255,7 +259,7 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { if (prevResult) currentHover = prevResult await displayPreview(prevResult) } - } else if (e.key === "ArrowDown" || e.key === "Tab") { + } else if (e.key === "ArrowDown" || e.key === "Tab" || (e.ctrlKey && e.key === "n")) { e.preventDefault() // The results should already been focused, so we need to find the next one. // The activeElement is the search bar, so we need to find the first result and focus it.