diff options
| author | Michael Howell <michael@notriddle.com> | 2022-05-02 15:50:01 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2022-05-05 09:39:45 -0700 |
| commit | 8b2147b4970a06377defd142fa932d2264d2aa5d (patch) | |
| tree | dafd833773ffb75da947250f3d61a1507e4bb82e /src/librustdoc/html/static | |
| parent | 21a121332b4c5e2302c46956564879c447d555b2 (diff) | |
| download | rust-8b2147b4970a06377defd142fa932d2264d2aa5d.tar.gz rust-8b2147b4970a06377defd142fa932d2264d2aa5d.zip | |
rustdoc: fix keyboard shortcuts and console log on search page
Diffstat (limited to 'src/librustdoc/html/static')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 2468d39ebc7..2bb850f994d 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -43,26 +43,33 @@ const TY_KEYWORD = itemTypes.indexOf("keyword"); // In the search display, allows to switch between tabs. function printTab(nb) { - if (nb === 0 || nb === 1 || nb === 2) { - searchState.currentTab = nb; - } - let nb_copy = nb; + let iter = 0; + let foundCurrentTab = false; + let foundCurrentResultSet = false; onEachLazy(document.getElementById("titles").childNodes, elem => { - if (nb_copy === 0) { + if (nb === iter) { addClass(elem, "selected"); + foundCurrentTab = true; } else { removeClass(elem, "selected"); } - nb_copy -= 1; + iter += 1; }); + iter = 0; onEachLazy(document.getElementById("results").childNodes, elem => { - if (nb === 0) { + if (nb === iter) { addClass(elem, "active"); + foundCurrentResultSet = true; } else { removeClass(elem, "active"); } - nb -= 1; + iter += 1; }); + if (foundCurrentTab && foundCurrentResultSet) { + searchState.currentTab = nb; + } else if (nb != 0) { + printTab(0); + } } /** @@ -1731,6 +1738,7 @@ window.initSearch = rawSearchIndex => { output += '<div id="titles">' + makeTabHeader(0, signatureTabTitle, ret_others[1]) + "</div>"; + currentTab = 0; } const resultsElem = document.createElement("div"); @@ -1746,12 +1754,16 @@ window.initSearch = rawSearchIndex => { } search.appendChild(resultsElem); // Reset focused elements. - searchState.focusedByTab = [null, null, null]; searchState.showResults(search); const elems = document.getElementById("titles").childNodes; - elems[0].onclick = () => { printTab(0); }; - elems[1].onclick = () => { printTab(1); }; - elems[2].onclick = () => { printTab(2); }; + searchState.focusedByTab = []; + let i = 0; + for (const elem of elems) { + const j = i; + elem.onclick = () => { printTab(j); }; + searchState.focusedByTab.push(null); + i += 1; + } printTab(currentTab); } |
