Skip to content

Commit 52755b7

Browse files
committed
auto merge of #12439 : cmr/rust/rustdoc-reset, r=thestinger
rustdoc: web: don't reset the search bar
2 parents 51676b2 + c9713ff commit 52755b7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustdoc/html/static/main.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@
114114
function initSearch(searchIndex) {
115115
var currentResults, index, params = getQueryStringParams();
116116

117-
// Populate search bar with query string search term when provided.
118-
$(".search-input")[0].value = params.search || '';
117+
// Populate search bar with query string search term when provided,
118+
// but only if the input bar is empty. This avoid the obnoxious issue
119+
// where you start trying to do a search, and the index loads, and
120+
// suddenly your search is gone!
121+
if ($(".search-input")[0].value === "") {
122+
$(".search-input")[0].value = params.search || '';
123+
}
119124

120125
/**
121126
* Executes the query and builds an index of results
@@ -574,8 +579,12 @@
574579
// When browsing forward to search results the previous search will be repeated,
575580
// so the currentResults are cleared to ensure the search is successful.
576581
currentResults = null;
577-
// Synchronize search bar with query string state and perform the search.
578-
$('.search-input').val(params.search);
582+
// Synchronize search bar with query string state and
583+
// perform the search, but don't empty the bar if there's
584+
// nothing there.
585+
if params.search !== undefined {
586+
$('.search-input').val(params.search);
587+
}
579588
// Some browsers fire 'onpopstate' for every page load (Chrome), while others fire the
580589
// event only when actually popping a state (Firefox), which is why search() is called
581590
// both here and at the end of the startSearch() function.

0 commit comments

Comments
 (0)