Route stray keystrokes into the search modal input

This commit is contained in:
dtonon 2026-08-12 22:24:11 +01:00
parent 2ab69e4cd3
commit 2c432b57e7

View file

@ -27,7 +27,20 @@
// Global "/" opens the search from any page, unless typing somewhere else
function onWindowKeydown(e: KeyboardEvent) {
if (searchModal.open) {
if (e.key === "Escape") closeSearch();
if (e.key === "Escape") {
closeSearch();
return;
}
// Typing fast right after "/" can outrun the async focus; route the
// keystroke into the input so no leading characters get lost
if (
e.key.length === 1 &&
!e.metaKey &&
!e.ctrlKey &&
!e.altKey &&
document.activeElement !== inputEl
)
inputEl?.focus();
return;
}
if (e.key !== "/" || e.metaKey || e.ctrlKey || e.altKey) return;