1
Fork 0

Fix escape key handling

This commit is contained in:
Guillaume Gomez 2020-05-28 14:51:12 +02:00
parent 698c5c6d95
commit bcf57d8f20

View file

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