Skip to content

Commit b6f3cb9

Browse files
committed
Auto merge of #86548 - GuillaumeGomez:fix-crate-filter-search-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 #86542 so it needs to wait for it before getting merged. r? `@jsha`
2 parents 2ce052b + c4023c6 commit b6f3cb9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/librustdoc/html/static/search.js

+4
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,10 @@ window.initSearch = function(rawSearchIndex) {
14421442
if (selectCrate) {
14431443
selectCrate.onchange = function() {
14441444
updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
1445+
// In case you "cut" the entry from the search input, then change the crate filter
1446+
// before paste back the previous search, you get the old search results without
1447+
// the filter. To prevent this, we need to remove the previous results.
1448+
currentResults = null;
14451449
search(undefined, true);
14461450
};
14471451
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
goto: file://|DOC_PATH|/test_docs/index.html
2+
write: (".search-input", "test")
3+
// Waiting for the search results to appear...
4+
wait-for: "#titles"
5+
assert-text: ("#results .externcrate", "test_docs")
6+
text: (".search-input", "")
7+
// We now want to change the crate filter.
8+
click: "#crate-search"
9+
// We select "lib2" option then press enter to change the filter.
10+
press-key: "ArrowDown"
11+
press-key: "Enter"
12+
// We now make the search again.
13+
write: (".search-input", "test")
14+
// Waiting for the search results to appear...
15+
wait-for: "#titles"
16+
// We check that there is no more "test_docs" appearing.
17+
assert-false: "#results .externcrate"

0 commit comments

Comments
 (0)