Browse Source

Merge pull request #2331 from rinagorsha/update-input-with-keyboard

[mod] Update input when selecting autocomplete prediction with keyboard
Markus Heiser 2 years ago
parent
commit
007bc73227

File diff suppressed because it is too large
+ 0 - 0
searx/static/themes/simple/js/searxng.min.js


File diff suppressed because it is too large
+ 0 - 0
searx/static/themes/simple/js/searxng.min.js.map


+ 33 - 0
searx/static/themes/simple/src/js/main/search.js

@@ -65,6 +65,39 @@
               }
             });
           },
+          _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);
+                }
+              },
+            }),
+            "Tab": Object.assign({}, AutoComplete.defaults.KeyboardMappings.Enter, {
+              Conditions: [{
+                Is: 9,
+                Not: false
+              }],
+              Callback: function (event) {
+                if (this.DOMResults.getAttribute("class").indexOf("open") != -1) {
+                  var liActive = this.DOMResults.querySelector("li.active");
+                  if (liActive !== null) {
+                    AutoComplete.defaults._Select.call(this, liActive);
+                    event.preventDefault();
+                  }
+                }
+              },
+            })
+          }),
         }, "#" + qinput_id);
       }
 

Some files were not shown because too many files changed in this diff