Browse Source

[mod] Update input when selecting by TAB

When the user press [TAB] the input form should be filled with the highlighted
item from the autocomplete list, but not release a search / with other words:
what we now have by pressing once on [ENTER] should be mapped to the [TAB] key
and pressing [ENTER] once should release a search query. [1]

[1] https://github.com/searxng/searxng/issues/778#issuecomment-1016593816

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Markus Heiser 2 years ago
parent
commit
962b4c719f
1 changed files with 15 additions and 0 deletions
  1. 15 0
      searx/static/themes/simple/src/js/main/search.js

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

@@ -82,6 +82,21 @@
                 }
                 }
               },
               },
             }),
             }),
+            "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);
         }, "#" + qinput_id);
       }
       }