add shortcut to focus searchbar

This commit is contained in:
flo 2024-02-09 21:33:40 +00:00
parent 459389a2da
commit a50d463700

View file

@ -37,8 +37,9 @@
searxng.ready(function () { searxng.ready(function () {
qinput = d.getElementById(qinput_id); qinput = d.getElementById(qinput_id);
const wasSearchBarFound = qinput !== null;
if (qinput !== null) { if (wasSearchBarFound) {
// clear button // clear button
createClearButton(qinput); createClearButton(qinput);
@ -155,7 +156,7 @@
// filter (safesearch, time range or language) (this requires JavaScript // filter (safesearch, time range or language) (this requires JavaScript
// though) // though)
if ( if (
qinput !== null wasSearchBarFound
&& searxng.settings.search_on_category_select && searxng.settings.search_on_category_select
// If .search_filters is undefined (invisible) we are on the homepage and // If .search_filters is undefined (invisible) we are on the homepage and
// hence don't have to set any listeners // 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); })(window, document, window.searxng);