about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-05-21 20:06:06 +0200
committerGitHub <noreply@github.com>2021-05-21 20:06:06 +0200
commit51a99eb603aaa87a4ef7eeaacebf4c7b01fe62dc (patch)
tree66d9d39f27cd0bff00e344522d0155762c3ff360
parentaf2ed1b51887ede4d766ee123d3fa216970d1fdd (diff)
parentb8909fc3c42effb78603c6e8c9d2920b098e75af (diff)
downloadrust-51a99eb603aaa87a4ef7eeaacebf4c7b01fe62dc.tar.gz
rust-51a99eb603aaa87a4ef7eeaacebf4c7b01fe62dc.zip
Rollup merge of #85506 - GuillaumeGomez:reset-focusedByTab, r=jsha
Reset "focusedByTab" field when doing another search

Fixes https://github.com/rust-lang/rust/issues/85467.

The problem was simply that we forget to reset the `focusedByTab` field, which was still referring to removed DOM elements.

r? ``@jsha``
-rw-r--r--src/librustdoc/html/static/search.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js
index 01cfffc5429..c95136d40d3 100644
--- a/src/librustdoc/html/static/search.js
+++ b/src/librustdoc/html/static/search.js
@@ -885,12 +885,12 @@ window.initSearch = function(rawSearchIndex) {
         focusSearchResult();
     }
 
-    // focus the first search result on the active tab, or the result that
+    // Focus the first search result on the active tab, or the result that
     // was focused last time this tab was active.
     function focusSearchResult() {
         var target = searchState.focusedByTab[searchState.currentTab] ||
-          document.querySelectorAll(".search-results.active a").item(0) ||
-          document.querySelectorAll("#titles > button").item(searchState.currentTab);
+            document.querySelectorAll(".search-results.active a").item(0) ||
+            document.querySelectorAll("#titles > button").item(searchState.currentTab);
         if (target) {
             target.focus();
         }
@@ -1076,6 +1076,8 @@ window.initSearch = function(rawSearchIndex) {
             ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";
 
         search.innerHTML = output;
+        // Reset focused elements.
+        searchState.focusedByTab = [null, null, null];
         searchState.showResults(search);
         var elems = document.getElementById("titles").childNodes;
         elems[0].onclick = function() { printTab(0); };
@@ -1365,7 +1367,6 @@ window.initSearch = function(rawSearchIndex) {
             if (e.which === 38) { // up
                 var previous = document.activeElement.previousElementSibling;
                 if (previous) {
-                    console.log("previousElementSibling", previous);
                     previous.focus();
                 } else {
                     searchState.focus();