@@ -2160,6 +2160,18 @@ function initSearch(rawSearchIndex) {
2160
2160
printTab ( currentTab ) ;
2161
2161
}
2162
2162
2163
+ function updateSearchHistory ( url ) {
2164
+ if ( ! browserSupportsHistoryApi ( ) ) {
2165
+ return ;
2166
+ }
2167
+ const params = searchState . getQueryStringParams ( ) ;
2168
+ if ( ! history . state && ! params . search ) {
2169
+ history . pushState ( null , "" , url ) ;
2170
+ } else {
2171
+ history . replaceState ( null , "" , url ) ;
2172
+ }
2173
+ }
2174
+
2163
2175
/**
2164
2176
* Perform a search based on the current state of the search input element
2165
2177
* and display the results.
@@ -2196,15 +2208,7 @@ function initSearch(rawSearchIndex) {
2196
2208
2197
2209
// Because searching is incremental by character, only the most
2198
2210
// recent search query is added to the browser history.
2199
- if ( browserSupportsHistoryApi ( ) ) {
2200
- const newURL = buildUrl ( query . original , filterCrates ) ;
2201
-
2202
- if ( ! history . state && ! params . search ) {
2203
- history . pushState ( null , "" , newURL ) ;
2204
- } else {
2205
- history . replaceState ( null , "" , newURL ) ;
2206
- }
2207
- }
2211
+ updateSearchHistory ( buildUrl ( query . original , filterCrates ) ) ;
2208
2212
2209
2213
showResults (
2210
2214
execQuery ( query , searchWords , filterCrates , window . currentCrate ) ,
@@ -2670,13 +2674,8 @@ function initSearch(rawSearchIndex) {
2670
2674
function updateCrate ( ev ) {
2671
2675
if ( ev . target . value === "all crates" ) {
2672
2676
// If we don't remove it from the URL, it'll be picked up again by the search.
2673
- const params = searchState . getQueryStringParams ( ) ;
2674
2677
const query = searchState . input . value . trim ( ) ;
2675
- if ( ! history . state && ! params . search ) {
2676
- history . pushState ( null , "" , buildUrl ( query , null ) ) ;
2677
- } else {
2678
- history . replaceState ( null , "" , buildUrl ( query , null ) ) ;
2679
- }
2678
+ updateSearchHistory ( buildUrl ( query , null ) ) ;
2680
2679
}
2681
2680
// In case you "cut" the entry from the search input, then change the crate filter
2682
2681
// before paste back the previous search, you get the old search results without
0 commit comments