Route stray keystrokes into the search modal input
This commit is contained in:
parent
2ab69e4cd3
commit
2c432b57e7
1 changed files with 14 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue