Skip to content

Commit

Permalink
Auto merge of rust-lang#86548 - GuillaumeGomez:fix-crate-filter-searc…
Browse files Browse the repository at this point in the history
…h-reset, r=jsha

Fix crate filter search reset

I found a fun bug when using rustdoc recently: I made a search, cut the search input content, changed the crate filter, pasted back the input content. To my surprise, the crate filter wasn't applied. It's because that our search input was empty when receiving the `<select>` "onchange" event. To fix this issue, I reset the `currentResults` variable to `null`.

It's using the first commit from rust-lang#86542 so it needs to wait for it before getting merged.

r? `@jsha`
  • Loading branch information
bors committed Jun 23, 2021
2 parents 2ce052b + c4023c6 commit b6f3cb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,10 @@ window.initSearch = function(rawSearchIndex) {
if (selectCrate) {
selectCrate.onchange = function() {
updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
// In case you "cut" the entry from the search input, then change the crate filter
// before paste back the previous search, you get the old search results without
// the filter. To prevent this, we need to remove the previous results.
currentResults = null;
search(undefined, true);
};
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc-gui/search-filter.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
goto: file://|DOC_PATH|/test_docs/index.html
write: (".search-input", "test")
// Waiting for the search results to appear...
wait-for: "#titles"
assert-text: ("#results .externcrate", "test_docs")
text: (".search-input", "")
// We now want to change the crate filter.
click: "#crate-search"
// We select "lib2" option then press enter to change the filter.
press-key: "ArrowDown"
press-key: "Enter"
// We now make the search again.
write: (".search-input", "test")
// Waiting for the search results to appear...
wait-for: "#titles"
// We check that there is no more "test_docs" appearing.
assert-false: "#results .externcrate"

0 comments on commit b6f3cb9

Please sign in to comment.