Fix keyboard handling of fulltext search results

This commit is contained in:
Jaifroid 2025-06-11 06:32:29 +01:00
parent 3bb40fb4b0
commit ec52b0a6b7
2 changed files with 7 additions and 8 deletions

View File

@ -1,8 +1,8 @@
/*!
* app.css : Main CSS of the application
*
* Copyright 2013-2019 Mossroy and contributors
* Licence GPL v3:
* Copyright 2013-2023 Mossroy, Jaifroid and contributors
* License GPL v3:
*
* This file is part of Kiwix.
*

View File

@ -285,28 +285,27 @@ prefixElement.addEventListener('keydown', function (e) {
document.getElementById('articleContent').focus();
keyPressHandled = true;
}
// Arrow-key selection code adapted from https://stackoverflow.com/a/14747926/9727685
// Arrow-key selection code adapted from https://stackoverflow.com/a/14747926/9727685
// IE11 produces "Down" instead of "ArrowDown" and "Up" instead of "ArrowUp"
if (/^((Arrow)?(Down|Up|Left|Right)|Enter)$/.test(e.key)) {
// User pressed Down arrow, Up arrow, Left arrow, Right arrow, or Enter
e.preventDefault();
e.stopPropagation();
// This is needed to prevent processing in the keyup event : https://stackoverflow.com/questions/9951274
keyPressHandled = true;
var activeElement = document.querySelector('#articleList .hover') || document.querySelector('#articleList a');
if (!activeElement) return;
// If user presses Enter or Right arrow, read the dirEntry or open snippet
if (/Enter|Right|Left/.test(e.key)) {
if (activeElement.classList.contains('hover') && !activeElement.classList.contains('snippet-container')) {
if (/Enter/.test(e.key) && activeElement.classList.contains('hover') && !activeElement.classList.contains('snippet-container')) {
var dirEntryId = activeElement.getAttribute('dirEntryId');
findDirEntryFromDirEntryIdAndLaunchArticleRead(decodeURIComponent(dirEntryId));
return;
} else if (activeElement.classList.contains('snippet-container')) {
e.preventDefault();
// Open the snippet container
uiUtil.toggleSnippet(activeElement);
return;
}
return;
}
e.preventDefault();
// If user presses ArrowDown...
// (NB selection is limited to arrow keys and Enter by regex above)
if (/Down/.test(e.key)) {