From c7dad445b5288b2e3f622de5831108bed00ad88d Mon Sep 17 00:00:00 2001 From: dtonon Date: Tue, 16 Jun 2026 15:27:41 +0100 Subject: [PATCH] Use / shortcut with key hint for search --- src/lib/components/SearchBox.svelte | 51 ++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/lib/components/SearchBox.svelte b/src/lib/components/SearchBox.svelte index cdcd24e..9920f15 100644 --- a/src/lib/components/SearchBox.svelte +++ b/src/lib/components/SearchBox.svelte @@ -8,6 +8,7 @@ let open = $state(false); let searching = $state(false); let activeIndex = $state(-1); + let inputEl = $state(null); let timer: ReturnType | null = null; let seq = 0; @@ -88,15 +89,46 @@ if (query.trim().length >= 2) open = true; } + // Global "/" shortcut, unless the user is typing somewhere else + function onWindowKeydown(e: KeyboardEvent) { + if (e.key !== "/" || e.metaKey || e.ctrlKey || e.altKey) return; + const t = e.target as HTMLElement | null; + if ( + t && + (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable) + ) + return; + e.preventDefault(); + inputEl?.focus(); + } + function onBlur() { // Delay so a mousedown on a result still lands setTimeout(() => close(), 120); } + +
+ -
{#if open}