From e9fb9f2705f9d91bfcb57016061d10c77e8ad0c0 Mon Sep 17 00:00:00 2001 From: rinagorsha Date: Sat, 8 Apr 2023 23:24:49 +0300 Subject: [PATCH] [mod] Update input when selecting autocomplete prediction with keyboard - Update input when selecting autocomplete prediction with keyboard - Search immediately by pressing enter key - Search immediately by clicking on an autocomplete suggestion Related: - https://github.com/searxng/searxng/issues/778 --- .../static/themes/simple/src/js/main/search.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/searx/static/themes/simple/src/js/main/search.js b/searx/static/themes/simple/src/js/main/search.js index 9ba3914be..ceb17958b 100644 --- a/searx/static/themes/simple/src/js/main/search.js +++ b/searx/static/themes/simple/src/js/main/search.js @@ -65,6 +65,24 @@ } }); }, + _Select: function (item) { + AutoComplete.defaults._Select.call(this, item); + var form = item.closest('form'); + if (form) { + form.submit(); + } + }, + KeyboardMappings: Object.assign({}, AutoComplete.defaults.KeyboardMappings, { + "KeyUpAndDown_up": Object.assign({}, AutoComplete.defaults.KeyboardMappings.KeyUpAndDown_up, { + Callback: function (event) { + AutoComplete.defaults.KeyboardMappings.KeyUpAndDown_up.Callback.call(this, event); + var liActive = this.DOMResults.querySelector("li.active"); + if (liActive) { + AutoComplete.defaults._Select.call(this, liActive); + } + }, + }), + }), }, "#" + qinput_id); }