@@ -91,6 +91,7 @@ function defocusSearchBar() {
91
91
92
92
var disableShortcuts = getCurrentValue ( "rustdoc-disable-shortcuts" ) === "true" ;
93
93
var search_input = getSearchInput ( ) ;
94
+ var searchTimeout = null ;
94
95
95
96
// On the search screen, so you remain on the last tab you opened.
96
97
//
@@ -101,6 +102,13 @@ function defocusSearchBar() {
101
102
102
103
var titleBeforeSearch = document . title ;
103
104
105
+ function clearInputTimeout ( ) {
106
+ if ( searchTimeout !== null ) {
107
+ clearTimeout ( searchTimeout ) ;
108
+ searchTimeout = null ;
109
+ }
110
+ }
111
+
104
112
function getPageId ( ) {
105
113
var id = document . location . href . split ( "#" ) [ 1 ] ;
106
114
if ( id ) {
@@ -355,6 +363,7 @@ function defocusSearchBar() {
355
363
if ( hasClass ( help , "hidden" ) === false ) {
356
364
displayHelp ( false , ev , help ) ;
357
365
} else if ( hasClass ( search , "hidden" ) === false ) {
366
+ clearInputTimeout ( ) ;
358
367
ev . preventDefault ( ) ;
359
368
hideSearchResults ( search ) ;
360
369
document . title = titleBeforeSearch ;
@@ -1810,9 +1819,8 @@ function defocusSearchBar() {
1810
1819
}
1811
1820
1812
1821
function startSearch ( ) {
1813
- var searchTimeout ;
1814
1822
var callback = function ( ) {
1815
- clearTimeout ( searchTimeout ) ;
1823
+ clearInputTimeout ( ) ;
1816
1824
if ( search_input . value . length === 0 ) {
1817
1825
if ( browserSupportsHistoryApi ( ) ) {
1818
1826
history . replaceState ( "" , window . currentCrate + " - Rust" , "?search=" ) ;
@@ -1826,7 +1834,7 @@ function defocusSearchBar() {
1826
1834
search_input . oninput = callback ;
1827
1835
document . getElementsByClassName ( "search-form" ) [ 0 ] . onsubmit = function ( e ) {
1828
1836
e . preventDefault ( ) ;
1829
- clearTimeout ( searchTimeout ) ;
1837
+ clearInputTimeout ( ) ;
1830
1838
search ( ) ;
1831
1839
} ;
1832
1840
search_input . onchange = function ( e ) {
@@ -1835,7 +1843,7 @@ function defocusSearchBar() {
1835
1843
return ;
1836
1844
}
1837
1845
// Do NOT e.preventDefault() here. It will prevent pasting.
1838
- clearTimeout ( searchTimeout ) ;
1846
+ clearInputTimeout ( ) ;
1839
1847
// zero-timeout necessary here because at the time of event handler execution the
1840
1848
// pasted content is not in the input field yet. Shouldn’t make any difference for
1841
1849
// change, though.
0 commit comments