Merge pull request #1322 from return42/fix-794

[fix] keyboard.js - highlightResult: don't steal focus on click event
This commit is contained in:
Paul Braeuning 2022-06-14 19:07:09 +02:00 committed by GitHub
commit d7a76f3772
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -34,7 +34,7 @@ searxng.ready(function () {
searxng.on('.result', 'click', function (e) { searxng.on('.result', 'click', function (e) {
if (!isElementInDetail(e.target)) { if (!isElementInDetail(e.target)) {
highlightResult(this)(true); highlightResult(this)(true, true);
let resultElement = getResultElement(e.target); let resultElement = getResultElement(e.target);
if (isImageResult(resultElement)) { if (isImageResult(resultElement)) {
e.preventDefault(); e.preventDefault();
@ -172,7 +172,7 @@ searxng.ready(function () {
} }
function highlightResult (which) { function highlightResult (which) {
return function (noScroll) { return function (noScroll, keepFocus) {
var current = document.querySelector('.result[data-vim-selected]'), var current = document.querySelector('.result[data-vim-selected]'),
effectiveWhich = which; effectiveWhich = which;
if (current === null) { if (current === null) {
@ -233,9 +233,11 @@ searxng.ready(function () {
if (next) { if (next) {
current.removeAttribute('data-vim-selected'); current.removeAttribute('data-vim-selected');
next.setAttribute('data-vim-selected', 'true'); next.setAttribute('data-vim-selected', 'true');
var link = next.querySelector('h3 a') || next.querySelector('a'); if (!keepFocus) {
if (link !== null) { var link = next.querySelector('h3 a') || next.querySelector('a');
link.focus(); if (link !== null) {
link.focus();
}
} }
if (!noScroll) { if (!noScroll) {
scrollPageToSelected(); scrollPageToSelected();