Skip to content

Commit

Permalink
Rollup merge of #66514 - GuillaumeGomez:fix-search-filter-save, r=kin…
Browse files Browse the repository at this point in the history
…nison

Fix selected crate search filter

Fixes #62929.

r? @kinnison
  • Loading branch information
Centril authored Nov 20, 2019
2 parents 5a84f9b + 00ef5c1 commit 4bd9168
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,9 @@ themePicker.onblur = handleThemeButtonsBlur;
v.push_str(&minify_replacer(
&format!("{}\n{}", variables.join(""), all_indexes.join("\n")),
options.enable_minification));
v.push_str("initSearch(searchIndex);addSearchOptions(searchIndex);");
// "addSearchOptions" has to be called first so the crate filtering can be set before the
// search might start (if it's set into the URL for example).
v.push_str("addSearchOptions(searchIndex);initSearch(searchIndex);");
cx.shared.fs.write(&dst, &v)?;
}
if options.enable_index_page {
Expand Down
25 changes: 10 additions & 15 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,21 +521,6 @@ function getSearchElement() {
var OUTPUT_DATA = 1;
var params = getQueryStringParams();

// Set the crate filter from saved storage, if the current page has the saved crate filter.
//
// If not, ignore the crate filter -- we want to support filtering for crates on sites like
// doc.rust-lang.org where the crates may differ from page to page while on the same domain.
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
if (savedCrate !== null) {
onEachLazy(document.getElementById("crate-search").getElementsByTagName("option"),
function(e) {
if (e.value === savedCrate) {
document.getElementById("crate-search").value = e.value;
return true;
}
});
}

// Populate search bar with query string search term when provided,
// but only if the input bar is empty. This avoid the obnoxious issue
// where you start trying to do a search, and the index loads, and
Expand Down Expand Up @@ -2629,11 +2614,21 @@ function getSearchElement() {
}
return 0;
});
var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
for (var i = 0; i < crates_text.length; ++i) {
var option = document.createElement("option");
option.value = crates_text[i];
option.innerText = crates_text[i];
elem.appendChild(option);
// Set the crate filter from saved storage, if the current page has the saved crate
// filter.
//
// If not, ignore the crate filter -- we want to support filtering for crates on sites
// like doc.rust-lang.org where the crates may differ from page to page while on the
// same domain.
if (crates_text[i] === savedCrate) {
elem.value = savedCrate;
}
}

if (search_input) {
Expand Down

0 comments on commit 4bd9168

Please sign in to comment.