« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/static/js')
-rw-r--r--src/static/js/client/sidebar-search.js22
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;