Skip to content

Commit 2f3708a

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

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

+12-2
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();
@@ -4648,8 +4647,19 @@ function registerSearchEvents() {
46484647
function updateCrate(ev) {
46494648
if (ev.target.value === "all crates") {
46504649
// If we don't remove it from the URL, it'll be picked up again by the search.
4651-
const query = searchState.input.value.trim();
4650+
const query = searchState.input.value.trim()
4651+
.replace(/crate:[a-zA-Z_0-9]+/, "");
46524652
updateSearchHistory(buildUrl(query, null));
4653+
searchState.input.value = query;
4654+
} else {
4655+
const crate = ev.target.value;
4656+
// add/update the `crate:` syntax in the search bar
4657+
let newquery = searchState.input.value
4658+
.replace(/crate:[a-zA-Z_0-9]+/, "crate:" + crate);
4659+
if (!newquery.includes("crate:")) {
4660+
newquery = "crate:" + crate + " " + searchState.input.value;
4661+
}
4662+
searchState.input.value = newquery;
46534663
}
46544664
// In case you "cut" the entry from the search input, then change the crate filter
46554665
// before paste back the previous search, you get the old search results without

0 commit comments

Comments
 (0)