@@ -4448,7 +4448,6 @@ function updateSearchHistory(url) {
44484448async 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() {
46484647function 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 ( / c r a t e : [ a - z A - 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 ( / c r a t e : [ a - z A - 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