summaryrefslogtreecommitdiff
path: root/searx/static/themes/simple/src/js/main
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2022-06-13 21:35:14 +0200
committerAlexandre Flament <alex@al-f.net>2022-06-13 21:35:14 +0200
commitfe1683c9c6fae8ccd16049912a13d0bb527d0e62 (patch)
tree249ec7ca8cceca237d2e1b2a55e8d0de2bb9eff8 /searx/static/themes/simple/src/js/main
parent9b0b6a2c90fa87a83bdff3ec646bbf200797c642 (diff)
downloadsearxng-fe1683c9c6fae8ccd16049912a13d0bb527d0e62.tar.gz
searxng-fe1683c9c6fae8ccd16049912a13d0bb527d0e62.zip
UX fix: when the user clicks on the search input, don't move the cursor at the end
Related to https://github.com/searxng/searxng/pull/1153#issuecomment-1154247988
Diffstat (limited to 'searx/static/themes/simple/src/js/main')
-rw-r--r--searx/static/themes/simple/src/js/main/keyboard.js7
-rw-r--r--searx/static/themes/simple/src/js/main/search.js20
2 files changed, 7 insertions, 20 deletions
diff --git a/searx/static/themes/simple/src/js/main/keyboard.js b/searx/static/themes/simple/src/js/main/keyboard.js
index f29ed86f4..0eb30b09f 100644
--- a/searx/static/themes/simple/src/js/main/keyboard.js
+++ b/searx/static/themes/simple/src/js/main/keyboard.js
@@ -317,7 +317,12 @@ searxng.ready(function () {
function searchInputFocus () {
window.scrollTo(0, 0);
- document.querySelector('#q').focus();
+ var q = document.querySelector('#q');
+ q.focus();
+ if (q.setSelectionRange) {
+ var len = q.value.length;
+ q.setSelectionRange(len, len);
+ }
}
function openResult (newTab) {
diff --git a/searx/static/themes/simple/src/js/main/search.js b/searx/static/themes/simple/src/js/main/search.js
index b96cf499d..97c9ea541 100644
--- a/searx/static/themes/simple/src/js/main/search.js
+++ b/searx/static/themes/simple/src/js/main/search.js
@@ -3,17 +3,10 @@
(function (w, d, searxng) {
'use strict';
- var firstFocus = true, qinput_id = "q", qinput;
+ var qinput_id = "q", qinput;
const isMobile = window.matchMedia("only screen and (max-width: 50em)").matches;
- function placeCursorAtEnd (element) {
- if (element.setSelectionRange) {
- var len = element.value.length;
- element.setSelectionRange(len, len);
- }
- }
-
function submitIfQuery () {
if (qinput.value.length > 0) {
var search = document.getElementById('search');
@@ -45,15 +38,6 @@
searxng.ready(function () {
qinput = d.getElementById(qinput_id);
- function placeCursorAtEndOnce () {
- if (firstFocus) {
- placeCursorAtEnd(qinput);
- firstFocus = false;
- } else {
- // e.preventDefault();
- }
- }
-
if (qinput !== null) {
// clear button
createClearButton(qinput);
@@ -84,8 +68,6 @@
}, "#" + qinput_id);
}
- qinput.addEventListener('focus', placeCursorAtEndOnce, false);
-
if (!isMobile && document.querySelector('.index_endpoint')) {
qinput.focus();
}