Skip to content

Commit 79e5b85

Browse files
committed
update the crate: part in searches when it is changed in the dropdown
1 parent 91f184c commit 79e5b85

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/librustdoc/html/static/js/search.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4448,7 +4448,6 @@ function updateSearchHistory(url) {
44484448
async function search(forced) {
44494449
const query = DocSearch.parseQuery(searchState.input.value.trim());
44504450
let filterCrates = getFilterCrates();
4451-
44524451
if (!forced && query.userQuery === currentResults) {
44534452
if (query.userQuery.length > 0) {
44544453
putBackSearch();
@@ -4650,6 +4649,15 @@ function updateCrate(ev) {
46504649
// If we don't remove it from the URL, it'll be picked up again by the search.
46514650
const query = searchState.input.value.trim();
46524651
updateSearchHistory(buildUrl(query, null));
4652+
} else {
4653+
const crate = ev.target.value;
4654+
// add/update the `crate:` syntax in the search bar
4655+
let newquery = searchState.input.value
4656+
.replace(/crate:[a-zA-Z_0-9]+/, "crate:"+crate);
4657+
if (!newquery.includes("crate:")) {
4658+
newquery = "crate:"+crate+" "+searchState.input.value;
4659+
}
4660+
searchState.input.value = newquery;
46534661
}
46544662
// In case you "cut" the entry from the search input, then change the crate filter
46554663
// before paste back the previous search, you get the old search results without

0 commit comments

Comments
 (0)