Skip to content

Fix escape key handling #72691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -91,6 +92,13 @@ function getSearchElement() {

var titleBeforeSearch = document.title;

function clearInputTimeout() {
if (searchTimeout !== null) {
clearTimeout(searchTimeout);
searchTimeout = null;
}
}

function getPageId() {
var id = document.location.href.split("#")[1];
if (id) {
Expand Down Expand Up @@ -344,6 +352,7 @@ function getSearchElement() {
if (hasClass(help, "hidden") === false) {
displayHelp(false, ev, help);
} else if (hasClass(search, "hidden") === false) {
clearInputTimeout();
ev.preventDefault();
hideSearchResults(search);
document.title = titleBeforeSearch;
Expand Down Expand Up @@ -1799,9 +1808,8 @@ function getSearchElement() {
}

function startSearch() {
var searchTimeout;
var callback = function() {
clearTimeout(searchTimeout);
clearInputTimeout();
if (search_input.value.length === 0) {
if (browserSupportsHistoryApi()) {
history.replaceState("", window.currentCrate + " - Rust", "?search=");
Expand All @@ -1815,7 +1823,7 @@ function getSearchElement() {
search_input.oninput = callback;
document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
e.preventDefault();
clearTimeout(searchTimeout);
clearInputTimeout();
search();
};
search_input.onchange = function(e) {
Expand All @@ -1824,7 +1832,7 @@ function getSearchElement() {
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.
Expand Down