diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-05-31 21:30:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-31 21:30:00 +0200 |
| commit | 6cd9a67314a07ecb29f096f821d76ea0855b1156 (patch) | |
| tree | b494b58b221d90302c3e9bd0d456204dfc5730c2 | |
| parent | f6072cab136beea206b7cfe79f8d10fccf5af591 (diff) | |
| parent | 7a2efa3a106389e9cd5c8bf3ab8f809398e77053 (diff) | |
| download | rust-6cd9a67314a07ecb29f096f821d76ea0855b1156.tar.gz rust-6cd9a67314a07ecb29f096f821d76ea0855b1156.zip | |
Rollup merge of #72691 - GuillaumeGomez:escape-key-handling, r=kinnison
Fix escape key handling Fixes #72647. The problem was that you could have a timeout just after the moment you press "escape", putting back the results. r? @kinnison
| -rw-r--r-- | src/librustdoc/html/static/main.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 22c9426db20..ac5a2f96b26 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -91,6 +91,7 @@ function defocusSearchBar() { 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. // @@ -101,6 +102,13 @@ function defocusSearchBar() { var titleBeforeSearch = document.title; + function clearInputTimeout() { + if (searchTimeout !== null) { + clearTimeout(searchTimeout); + searchTimeout = null; + } + } + function getPageId() { var id = document.location.href.split("#")[1]; if (id) { @@ -355,6 +363,7 @@ function defocusSearchBar() { if (hasClass(help, "hidden") === false) { displayHelp(false, ev, help); } else if (hasClass(search, "hidden") === false) { + clearInputTimeout(); ev.preventDefault(); hideSearchResults(search); document.title = titleBeforeSearch; @@ -1810,9 +1819,8 @@ function defocusSearchBar() { } function startSearch() { - var searchTimeout; var callback = function() { - clearTimeout(searchTimeout); + clearInputTimeout(); if (search_input.value.length === 0) { if (browserSupportsHistoryApi()) { history.replaceState("", window.currentCrate + " - Rust", "?search="); @@ -1826,7 +1834,7 @@ function defocusSearchBar() { search_input.oninput = callback; document.getElementsByClassName("search-form")[0].onsubmit = function(e) { e.preventDefault(); - clearTimeout(searchTimeout); + clearInputTimeout(); search(); }; search_input.onchange = function(e) { @@ -1835,7 +1843,7 @@ function defocusSearchBar() { return; } // Do NOT e.preventDefault() here. It will prevent pasting. - clearTimeout(searchTimeout); + clearInputTimeout(); // 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. |
