Skip to content

Commit

Permalink
[fix] keyboard.js - highlightResult: don't steal focus on click event
Browse files Browse the repository at this point in the history
For keyboard navigation the highlightResult() function in keyboard.js steals the
focus.  On a mouse click event (non keyboard action) the focus should resist
where it is, otherwise a marked region gets lost.  This is the reason why text
can't be selected when using simple theme with JS enabled.

Closes: searxng#794
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
  • Loading branch information
return42 committed Jun 14, 2022
1 parent 9b0b6a2 commit c9d2975
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions searx/static/themes/simple/src/js/main/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ searxng.ready(function () {

searxng.on('.result', 'click', function (e) {
if (!isElementInDetail(e.target)) {
highlightResult(this)(true);
highlightResult(this)(true, true);
let resultElement = getResultElement(e.target);
if (isImageResult(resultElement)) {
e.preventDefault();
Expand Down Expand Up @@ -172,7 +172,7 @@ searxng.ready(function () {
}

function highlightResult (which) {
return function (noScroll) {
return function (noScroll, keepFocus) {
var current = document.querySelector('.result[data-vim-selected]'),
effectiveWhich = which;
if (current === null) {
Expand Down Expand Up @@ -233,9 +233,11 @@ searxng.ready(function () {
if (next) {
current.removeAttribute('data-vim-selected');
next.setAttribute('data-vim-selected', 'true');
var link = next.querySelector('h3 a') || next.querySelector('a');
if (link !== null) {
link.focus();
if (!keepFocus) {
var link = next.querySelector('h3 a') || next.querySelector('a');
if (link !== null) {
link.focus();
}
}
if (!noScroll) {
scrollPageToSelected();
Expand Down

0 comments on commit c9d2975

Please sign in to comment.