Skip to content

Commit 6cd9a67

Browse files
authored
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
2 parents f6072ca + 7a2efa3 commit 6cd9a67

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/librustdoc/html/static/main.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function defocusSearchBar() {
9191

9292
var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
9393
var search_input = getSearchInput();
94+
var searchTimeout = null;
9495

9596
// On the search screen, so you remain on the last tab you opened.
9697
//
@@ -101,6 +102,13 @@ function defocusSearchBar() {
101102

102103
var titleBeforeSearch = document.title;
103104

105+
function clearInputTimeout() {
106+
if (searchTimeout !== null) {
107+
clearTimeout(searchTimeout);
108+
searchTimeout = null;
109+
}
110+
}
111+
104112
function getPageId() {
105113
var id = document.location.href.split("#")[1];
106114
if (id) {
@@ -355,6 +363,7 @@ function defocusSearchBar() {
355363
if (hasClass(help, "hidden") === false) {
356364
displayHelp(false, ev, help);
357365
} else if (hasClass(search, "hidden") === false) {
366+
clearInputTimeout();
358367
ev.preventDefault();
359368
hideSearchResults(search);
360369
document.title = titleBeforeSearch;
@@ -1810,9 +1819,8 @@ function defocusSearchBar() {
18101819
}
18111820

18121821
function startSearch() {
1813-
var searchTimeout;
18141822
var callback = function() {
1815-
clearTimeout(searchTimeout);
1823+
clearInputTimeout();
18161824
if (search_input.value.length === 0) {
18171825
if (browserSupportsHistoryApi()) {
18181826
history.replaceState("", window.currentCrate + " - Rust", "?search=");
@@ -1826,7 +1834,7 @@ function defocusSearchBar() {
18261834
search_input.oninput = callback;
18271835
document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
18281836
e.preventDefault();
1829-
clearTimeout(searchTimeout);
1837+
clearInputTimeout();
18301838
search();
18311839
};
18321840
search_input.onchange = function(e) {
@@ -1835,7 +1843,7 @@ function defocusSearchBar() {
18351843
return;
18361844
}
18371845
// Do NOT e.preventDefault() here. It will prevent pasting.
1838-
clearTimeout(searchTimeout);
1846+
clearInputTimeout();
18391847
// zero-timeout necessary here because at the time of event handler execution the
18401848
// pasted content is not in the input field yet. Shouldn’t make any difference for
18411849
// change, though.

0 commit comments

Comments
 (0)