Skip to content

Commit 4bd9168

Browse files
authored
Rollup merge of #66514 - GuillaumeGomez:fix-search-filter-save, r=kinnison
Fix selected crate search filter Fixes #62929. r? @kinnison
2 parents 5a84f9b + 00ef5c1 commit 4bd9168

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
@@ -882,7 +882,9 @@ themePicker.onblur = handleThemeButtonsBlur;
882882
v.push_str(&minify_replacer(
883883
&format!("{}\n{}", variables.join(""), all_indexes.join("\n")),
884884
options.enable_minification));
885-
v.push_str("initSearch(searchIndex);addSearchOptions(searchIndex);");
885+
// "addSearchOptions" has to be called first so the crate filtering can be set before the
886+
// search might start (if it's set into the URL for example).
887+
v.push_str("addSearchOptions(searchIndex);initSearch(searchIndex);");
886888
cx.shared.fs.write(&dst, &v)?;
887889
}
888890
if options.enable_index_page {

src/librustdoc/html/static/main.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -521,21 +521,6 @@ function getSearchElement() {
521521
var OUTPUT_DATA = 1;
522522
var params = getQueryStringParams();
523523

524-
// Set the crate filter from saved storage, if the current page has the saved crate filter.
525-
//
526-
// If not, ignore the crate filter -- we want to support filtering for crates on sites like
527-
// doc.rust-lang.org where the crates may differ from page to page while on the same domain.
528-
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
529-
if (savedCrate !== null) {
530-
onEachLazy(document.getElementById("crate-search").getElementsByTagName("option"),
531-
function(e) {
532-
if (e.value === savedCrate) {
533-
document.getElementById("crate-search").value = e.value;
534-
return true;
535-
}
536-
});
537-
}
538-
539524
// Populate search bar with query string search term when provided,
540525
// but only if the input bar is empty. This avoid the obnoxious issue
541526
// where you start trying to do a search, and the index loads, and
@@ -2629,11 +2614,21 @@ function getSearchElement() {
26292614
}
26302615
return 0;
26312616
});
2617+
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
26322618
for (var i = 0; i < crates_text.length; ++i) {
26332619
var option = document.createElement("option");
26342620
option.value = crates_text[i];
26352621
option.innerText = crates_text[i];
26362622
elem.appendChild(option);
2623+
// Set the crate filter from saved storage, if the current page has the saved crate
2624+
// filter.
2625+
//
2626+
// If not, ignore the crate filter -- we want to support filtering for crates on sites
2627+
// like doc.rust-lang.org where the crates may differ from page to page while on the
2628+
// same domain.
2629+
if (crates_text[i] === savedCrate) {
2630+
elem.value = savedCrate;
2631+
}
26372632
}
26382633

26392634
if (search_input) {

0 commit comments

Comments
 (0)