]> git.lizzy.rs Git - rust.git/commitdiff
Fix escape key handling
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 28 May 2020 12:51:12 +0000 (14:51 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 28 May 2020 12:51:12 +0000 (14:51 +0200)
src/librustdoc/html/static/main.js

index 9869c50fbb0cf10a7f8096d66dabb8f3aa3fdc5d..c349b59e562a9154308ddc96140d18094121df58 100644 (file)
@@ -81,6 +81,7 @@ function getSearchElement() {
 
     var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
     var search_input = getSearchInput();
+    var searchTimeout = null;
 
     // On the search screen, so you remain on the last tab you opened.
     //
@@ -344,6 +345,10 @@ function getSearchElement() {
         if (hasClass(help, "hidden") === false) {
             displayHelp(false, ev, help);
         } else if (hasClass(search, "hidden") === false) {
+            if (searchTimeout !== null) {
+                clearTimeout(searchTimeout);
+                searchTimeout = null;
+            }
             ev.preventDefault();
             hideSearchResults(search);
             document.title = titleBeforeSearch;
@@ -1799,7 +1804,6 @@ function getSearchElement() {
         }
 
         function startSearch() {
-            var searchTimeout;
             var callback = function() {
                 clearTimeout(searchTimeout);
                 if (search_input.value.length === 0) {
@@ -1815,7 +1819,10 @@ function getSearchElement() {
             search_input.oninput = callback;
             document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
                 e.preventDefault();
-                clearTimeout(searchTimeout);
+                if (searchTimeout !== null) {
+                    clearTimeout(searchTimeout);
+                    searchTimeout = null;
+                }
                 search();
             };
             search_input.onchange = function(e) {
@@ -1824,7 +1831,10 @@ function getSearchElement() {
                     return;
                 }
                 // Do NOT e.preventDefault() here. It will prevent pasting.
-                clearTimeout(searchTimeout);
+                if (searchTimeout !== null) {
+                    clearTimeout(searchTimeout);
+                    searchTimeout = null;
+                }
                 // zero-timeout necessary here because at the time of event handler execution the
                 // pasted content is not in the input field yet. Shouldn’t make any difference for
                 // change, though.