diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-01-10 18:24:34 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-01-10 18:51:26 -0400 |
commit | c7d233c4bc1f7bd8f8c3205b6683022c31a43b5f (patch) | |
tree | acb0eab140fb0088fd0853f5d4129f1564865c32 /src/static/js | |
parent | af518f1236a8ae22b45d2ab05ecb44430398dde2 (diff) |
client: factor out focusFirstSidebarSearchResult
Diffstat (limited to 'src/static/js')
-rw-r--r-- | src/static/js/client/sidebar-search.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js index ef64a259..4f0c2d8f 100644 --- a/src/static/js/client/sidebar-search.js +++ b/src/static/js/client/sidebar-search.js @@ -357,7 +357,7 @@ export function addPageListeners() { domEvent.preventDefault(); } - if (domEvent.key === 'ArrowDown') handleDown: { + if (domEvent.key === 'ArrowDown') { if (state.stoppedTypingTimeout) { clearTimeout(state.stoppedTypingTimeout); state.stoppedTypingTimeout = null; @@ -368,13 +368,8 @@ export function addPageListeners() { }, settings.pressDownToFocusFirstResultLatency); activateSidebarSearch(info.searchInput.value); - - break handleDown; - } - - const elem = info.results.firstChild; - if (elem?.classList.contains('wiki-search-result')) { - elem.focus({focusVisible: true}); + } else { + focusFirstSidebarSearchResult(); } } }); @@ -504,7 +499,7 @@ async function activateSidebarSearch(query) { clearTimeout(state.focusFirstResultTimeout); state.focusFirstResultTimeout = null; if (!state.stoppedTypingTimeout) { - info.results.firstChild?.focus(); + focusFirstSidebarSearchResult(); } } } @@ -866,6 +861,15 @@ function hideSidebarSearchResults() { cssProp(info.endSearchLine, 'display', 'none'); } +function focusFirstSidebarSearchResult() { + const elem = info.results.firstChild; + if (!elem?.classList.contains('wiki-search-result')) { + return; + } + + elem.focus({focusVisible: true}); +} + function saveSidebarSearchResultsScrollOffset() { const {session} = info; |