From a304741f2358544406533a15a4b0b1a9a7a8077e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 12 Feb 2025 06:43:14 -0400 Subject: client: sidebar-search: mouse dynamics when recalling This commit is a bit misleading because the work here actually replaced an attempt at using .select(). --- src/static/js/client/sidebar-search.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js index 2e350070..a5652412 100644 --- a/src/static/js/client/sidebar-search.js +++ b/src/static/js/client/sidebar-search.js @@ -72,6 +72,7 @@ export const info = { collapsedDetailsForTidiness: null, recallingRecentSearch: null, + recallingRecentSearchFromMouse: null, currentValue: null, @@ -317,6 +318,14 @@ export function mutatePageContent() { export function addPageListeners() { if (!info.searchInput) return; + info.searchInput.addEventListener('mousedown', _domEvent => { + const {state} = info; + + if (state.recallingRecentSearch) { + state.recallingRecentSearchFromMouse = true; + } + }); + info.searchInput.addEventListener('focus', _domEvent => { const {session, state} = info; @@ -328,6 +337,19 @@ export function addPageListeners() { } }); + info.searchLabel.addEventListener('click', domEvent => { + const {state} = info; + + if (state.recallingRecentSearchFromMouse) { + if (info.searchInput.selectionStart === info.searchInput.selectionEnd) { + info.searchInput.select(); + } + + state.recallingRecentSearchFromMouse = false; + return; + } + }); + info.searchInput.addEventListener('change', _domEvent => { const {state} = info; -- cgit 1.3.0-6-gf8a5