mirror of https://github.com/searxng/searxng.git
[fix] keyboard.js - highlightResult: don't steal focus on click event
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: https://github.com/searxng/searxng/issues/794 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
7bc3d17b11
commit
882282d0e9
|
@ -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,10 +233,12 @@ 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');
|
||||||
|
if (!keepFocus) {
|
||||||
var link = next.querySelector('h3 a') || next.querySelector('a');
|
var link = next.querySelector('h3 a') || next.querySelector('a');
|
||||||
if (link !== null) {
|
if (link !== null) {
|
||||||
link.focus();
|
link.focus();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!noScroll) {
|
if (!noScroll) {
|
||||||
scrollPageToSelected();
|
scrollPageToSelected();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue