From 92d0c378e01e277e87b13537bc6942994b320d2d Mon Sep 17 00:00:00 2001 From: Jinyuan Huang <88757735+BernieHuang2008@users.noreply.github.com> Date: Sat, 16 Sep 2023 09:53:59 +0000 Subject: [PATCH] [fix] keyboard navigation / simple theme (UI) - avoid loop select - fix select next item in mixed result lists Replaces: https://github.com/searxng/searxng/pull/2789 Closes: https://github.com/searxng/searxng/issues/2751 Closes: https://github.com/searxng/searxng/issues/2788 --- AUTHORS.rst | 3 ++- searx/static/themes/simple/src/js/main/keyboard.js | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 58fed35c9..8692c03d4 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -168,4 +168,5 @@ features or generally made searx better: - Milad Laly @Milad-Laly - @llmII - @blob42 ``_ -- Paolo Basso `` \ No newline at end of file +- Paolo Basso `` +- Bernie Huang `` \ No newline at end of file diff --git a/searx/static/themes/simple/src/js/main/keyboard.js b/searx/static/themes/simple/src/js/main/keyboard.js index 4a6f9d384..5c02acbfd 100644 --- a/searx/static/themes/simple/src/js/main/keyboard.js +++ b/searx/static/themes/simple/src/js/main/keyboard.js @@ -213,6 +213,7 @@ searxng.ready(function () { } var next, results = document.querySelectorAll('.result'); + results = Array.from(results); // convert NodeList to Array for further use if (typeof effectiveWhich !== 'string') { next = effectiveWhich; @@ -233,16 +234,10 @@ searxng.ready(function () { } break; case 'down': - next = current.nextElementSibling; - if (next === null) { - next = results[0]; - } + next = results[results.indexOf(current) + 1] || current; break; case 'up': - next = current.previousElementSibling; - if (next === null) { - next = results[results.length - 1]; - } + next = results[results.indexOf(current) - 1] || current; break; case 'bottom': next = results[results.length - 1];