[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
This commit is contained in:
rinagorsha 2023-04-08 23:24:49 +03:00 committed by Markus Heiser
parent 3372fcdb49
commit e9fb9f2705
1 changed files with 18 additions and 0 deletions

View File

@ -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);
}