Compare commits

...

1 Commits

Author SHA1 Message Date
Aaron Pham
08c0302e56
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 <contact@aarnphm.xyz>
2024-08-29 16:41:11 -04:00

View File

@ -242,7 +242,11 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
await displayPreview(anchor) await displayPreview(anchor)
anchor.click() 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() e.preventDefault()
if (results?.contains(document.activeElement)) { if (results?.contains(document.activeElement)) {
// If an element in results-container already has focus, focus previous one // 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 if (prevResult) currentHover = prevResult
await displayPreview(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() e.preventDefault()
// The results should already been focused, so we need to find the next one. // 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. // The activeElement is the search bar, so we need to find the first result and focus it.