Skip to content

Commit 00ef5c1

Browse files
Fix selected crate search filter
1 parent 9b0214d commit 00ef5c1

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/librustdoc/html/render.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,9 @@ themePicker.onblur = handleThemeButtonsBlur;
883883
v.push_str(&minify_replacer(
884884
&format!("{}\n{}", variables.join(""), all_indexes.join("\n")),
885885
options.enable_minification));
886-
v.push_str("initSearch(searchIndex);addSearchOptions(searchIndex);");
886+
// "addSearchOptions" has to be called first so the crate filtering can be set before the
887+
// search might start (if it's set into the URL for example).
888+
v.push_str("addSearchOptions(searchIndex);initSearch(searchIndex);");
887889
cx.shared.fs.write(&dst, &v)?;
888890
}
889891
if options.enable_index_page {

src/librustdoc/html/static/main.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,6 @@ function getSearchElement() {
512512
var OUTPUT_DATA = 1;
513513
var params = getQueryStringParams();
514514

515-
// Set the crate filter from saved storage, if the current page has the saved crate filter.
516-
//
517-
// If not, ignore the crate filter -- we want to support filtering for crates on sites like
518-
// doc.rust-lang.org where the crates may differ from page to page while on the same domain.
519-
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
520-
if (savedCrate !== null) {
521-
onEachLazy(document.getElementById("crate-search").getElementsByTagName("option"),
522-
function(e) {
523-
if (e.value === savedCrate) {
524-
document.getElementById("crate-search").value = e.value;
525-
return true;
526-
}
527-
});
528-
}
529-
530515
// Populate search bar with query string search term when provided,
531516
// but only if the input bar is empty. This avoid the obnoxious issue
532517
// where you start trying to do a search, and the index loads, and
@@ -2620,11 +2605,21 @@ function getSearchElement() {
26202605
}
26212606
return 0;
26222607
});
2608+
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
26232609
for (var i = 0; i < crates_text.length; ++i) {
26242610
var option = document.createElement("option");
26252611
option.value = crates_text[i];
26262612
option.innerText = crates_text[i];
26272613
elem.appendChild(option);
2614+
// Set the crate filter from saved storage, if the current page has the saved crate
2615+
// filter.
2616+
//
2617+
// If not, ignore the crate filter -- we want to support filtering for crates on sites
2618+
// like doc.rust-lang.org where the crates may differ from page to page while on the
2619+
// same domain.
2620+
if (crates_text[i] === savedCrate) {
2621+
elem.value = savedCrate;
2622+
}
26282623
}
26292624
}
26302625

0 commit comments

Comments
 (0)