Autodoc: fix search results navigation

Closes #17013
This commit is contained in:
Ian Johnson 2023-09-03 23:19:41 -04:00 committed by Loris Cro
parent 4d1432299f
commit 2f26b15995

View File

@ -4013,9 +4013,10 @@ Happy writing!
return; return;
} }
let liDom = domListSearchResults.children[curSearchIndex]; const searchResults = domListSearchResults.getElementsByTagName("li");
if (liDom == null && domListSearchResults.children.length !== 0) { let liDom = searchResults[curSearchIndex];
liDom = domListSearchResults.children[0]; if (liDom == null && searchResults.length !== 0) {
liDom = searchResults[0];
} }
if (liDom != null) { if (liDom != null) {
let aDom = liDom.children[0]; let aDom = liDom.children[0];
@ -4110,14 +4111,15 @@ Happy writing!
} }
function moveSearchCursor(dir) { function moveSearchCursor(dir) {
const searchResults = domListSearchResults.getElementsByTagName("li");
if ( if (
curSearchIndex < 0 || curSearchIndex < 0 ||
curSearchIndex >= domListSearchResults.children.length curSearchIndex >= searchResults.length
) { ) {
if (dir > 0) { if (dir > 0) {
curSearchIndex = -1 + dir; curSearchIndex = -1 + dir;
} else if (dir < 0) { } else if (dir < 0) {
curSearchIndex = domListSearchResults.children.length + dir; curSearchIndex = searchResults.length + dir;
} }
} else { } else {
curSearchIndex += dir; curSearchIndex += dir;
@ -4125,8 +4127,8 @@ Happy writing!
if (curSearchIndex < 0) { if (curSearchIndex < 0) {
curSearchIndex = 0; curSearchIndex = 0;
} }
if (curSearchIndex >= domListSearchResults.children.length) { if (curSearchIndex >= searchResults.length) {
curSearchIndex = domListSearchResults.children.length - 1; curSearchIndex = searchResults.length - 1;
} }
renderSearchCursor(); renderSearchCursor();
} }
@ -4465,8 +4467,9 @@ Happy writing!
function renderSearchCursor() { function renderSearchCursor() {
for (let i = 0; i < domListSearchResults.children.length; i += 1) { const searchResults = domListSearchResults.getElementsByTagName("li");
let liDom = domListSearchResults.children[i]; for (let i = 0; i < searchResults.length; i += 1) {
let liDom = searchResults[i];
if (curSearchIndex === i) { if (curSearchIndex === i) {
liDom.classList.add("selected"); liDom.classList.add("selected");
} else { } else {