@@ -4448,7 +4448,6 @@ function updateSearchHistory(url) {
4448
4448
async function search ( forced ) {
4449
4449
const query = DocSearch . parseQuery ( searchState . input . value . trim ( ) ) ;
4450
4450
let filterCrates = getFilterCrates ( ) ;
4451
-
4452
4451
if ( ! forced && query . userQuery === currentResults ) {
4453
4452
if ( query . userQuery . length > 0 ) {
4454
4453
putBackSearch ( ) ;
@@ -4648,8 +4647,19 @@ function registerSearchEvents() {
4648
4647
function updateCrate ( ev ) {
4649
4648
if ( ev . target . value === "all crates" ) {
4650
4649
// 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 ] + / , "" ) ;
4652
4652
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 ;
4653
4663
}
4654
4664
// In case you "cut" the entry from the search input, then change the crate filter
4655
4665
// before paste back the previous search, you get the old search results without
0 commit comments