From a50d46370076707e73910bbe5263d30d66468dcd Mon Sep 17 00:00:00 2001 From: flo <41804849+thecijal@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:33:40 +0000 Subject: [PATCH] add shortcut to focus searchbar --- searx/static/themes/simple/src/js/main/search.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/searx/static/themes/simple/src/js/main/search.js b/searx/static/themes/simple/src/js/main/search.js index ac1ece535..6aa7f03e1 100644 --- a/searx/static/themes/simple/src/js/main/search.js +++ b/searx/static/themes/simple/src/js/main/search.js @@ -37,8 +37,9 @@ searxng.ready(function () { qinput = d.getElementById(qinput_id); + const wasSearchBarFound = qinput !== null; - if (qinput !== null) { + if (wasSearchBarFound) { // clear button createClearButton(qinput); @@ -155,7 +156,7 @@ // filter (safesearch, time range or language) (this requires JavaScript // though) if ( - qinput !== null + wasSearchBarFound && searxng.settings.search_on_category_select // If .search_filters is undefined (invisible) we are on the homepage and // hence don't have to set any listeners @@ -181,6 +182,17 @@ }) } } + + // shortcut to focus search bar + if (wasSearchBarFound) { + d.addEventListener('keyup', function (event) { + if (event.key == "/") { + const queryLength = qinput.value.length; + qinput.setSelectionRange(queryLength, queryLength); + qinput.focus(); + } + }); + } }); })(window, document, window.searxng);