File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
src/librustdoc/html/static/js Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -277,14 +277,18 @@ function preLoadCss(cssUrl) {
277
277
searchState . mouseMovedAfterSearch = false ;
278
278
document . title = searchState . title ;
279
279
} ,
280
- hideResults : ( ) => {
281
- switchDisplayedElement ( null ) ;
280
+ removeQueryParameters : ( ) => {
281
+ // We change the document title.
282
282
document . title = searchState . titleBeforeSearch ;
283
- // We also remove the query parameter from the URL.
284
283
if ( browserSupportsHistoryApi ( ) ) {
285
284
history . replaceState ( null , "" , getNakedUrl ( ) + window . location . hash ) ;
286
285
}
287
286
} ,
287
+ hideResults : ( ) => {
288
+ switchDisplayedElement ( null ) ;
289
+ // We also remove the query parameter from the URL.
290
+ searchState . removeQueryParameters ( ) ;
291
+ } ,
288
292
getQueryStringParams : ( ) => {
289
293
const params = { } ;
290
294
window . location . search . substring ( 1 ) . split ( "&" ) .
Original file line number Diff line number Diff line change @@ -2046,6 +2046,20 @@ function initSearch(rawSearchIndex) {
2046
2046
if ( go_to_first || ( results . others . length === 1
2047
2047
&& getSettingValue ( "go-to-only-result" ) === "true" )
2048
2048
) {
2049
+ // Needed to force re-execution of JS when coming back to a page. Let's take this
2050
+ // scenario as example:
2051
+ //
2052
+ // 1. You have the "Directly go to item in search if there is only one result" option
2053
+ // enabled.
2054
+ // 2. You make a search which results only one result, leading you automatically to
2055
+ // this result.
2056
+ // 3. You go back to previous page.
2057
+ //
2058
+ // Now, without the call below, the JS will not be re-executed and the previous state
2059
+ // will be used, starting search again since the search input is not empty, leading you
2060
+ // back to the previous page again.
2061
+ window . onunload = ( ) => { } ;
2062
+ searchState . removeQueryParameters ( ) ;
2049
2063
const elem = document . createElement ( "a" ) ;
2050
2064
elem . href = results . others [ 0 ] . href ;
2051
2065
removeClass ( elem , "active" ) ;
@@ -2182,7 +2196,6 @@ function initSearch(rawSearchIndex) {
2182
2196
if ( e ) {
2183
2197
e . preventDefault ( ) ;
2184
2198
}
2185
-
2186
2199
const query = parseQuery ( searchState . input . value . trim ( ) ) ;
2187
2200
let filterCrates = getFilterCrates ( ) ;
2188
2201
You can’t perform that action at this time.
0 commit comments