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 * app.css : Main CSS of the application
* *
* Copyright 2013-2019 Mossroy and contributors * Copyright 2013-2023 Mossroy, Jaifroid and contributors
* Licence GPL v3: * License GPL v3:
* *
* This file is part of Kiwix. * This file is part of Kiwix.
* *

View File

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