« get me outta code hell

client: cancel focus first search result when text cursor moves - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/js/client/sidebar-search.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-10 18:45:44 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-10 18:51:27 -0400
commit085ab0e889f1a3182dffb9f48cf33aff013f22ec (patch)
treeab69f13562514bfed564f1da888218feadbf5809 /src/static/js/client/sidebar-search.js
parentb05383e49bc1de21997321afb468905eb7cefb1d (diff)
client: cancel focus first search result when text cursor moves
HTMLInputElement: selectionchange still not available, boo hoo

although this is probably appropriate wrt selection moving
literally anywhere else - should also cancel focus-first-result
Diffstat (limited to 'src/static/js/client/sidebar-search.js')
-rw-r--r--src/static/js/client/sidebar-search.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js
index 10ccf1b5..c79fb837 100644
--- a/src/static/js/client/sidebar-search.js
+++ b/src/static/js/client/sidebar-search.js
@@ -376,6 +376,15 @@ export function addPageListeners() {
     }
   });
 
+  document.addEventListener('selectionchange', _domEvent => {
+    const {state} = info;
+
+    if (state.focusFirstResultTimeout) {
+      clearTimeout(state.focusFirstResultTimeout);
+      state.focusFirstResultTimeout = null;
+    }
+  });
+
   info.endSearchLink.addEventListener('click', domEvent => {
     domEvent.preventDefault();
     clearSidebarSearch();