This repository was archived by the owner on May 28, 2025. It is now read-only.
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) {
277277 searchState . mouseMovedAfterSearch = false ;
278278 document . title = searchState . title ;
279279 } ,
280- hideResults : ( ) => {
281- switchDisplayedElement ( null ) ;
280+ removeQueryParameters : ( ) => {
281+ // We change the document title.
282282 document . title = searchState . titleBeforeSearch ;
283- // We also remove the query parameter from the URL.
284283 if ( browserSupportsHistoryApi ( ) ) {
285284 history . replaceState ( null , "" , getNakedUrl ( ) + window . location . hash ) ;
286285 }
287286 } ,
287+ hideResults : ( ) => {
288+ switchDisplayedElement ( null ) ;
289+ // We also remove the query parameter from the URL.
290+ searchState . removeQueryParameters ( ) ;
291+ } ,
288292 getQueryStringParams : ( ) => {
289293 const params = { } ;
290294 window . location . search . substring ( 1 ) . split ( "&" ) .
Original file line number Diff line number Diff line change @@ -2046,6 +2046,20 @@ function initSearch(rawSearchIndex) {
20462046 if ( go_to_first || ( results . others . length === 1
20472047 && getSettingValue ( "go-to-only-result" ) === "true" )
20482048 ) {
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 ( ) ;
20492063 const elem = document . createElement ( "a" ) ;
20502064 elem . href = results . others [ 0 ] . href ;
20512065 removeClass ( elem , "active" ) ;
@@ -2182,7 +2196,6 @@ function initSearch(rawSearchIndex) {
21822196 if ( e ) {
21832197 e . preventDefault ( ) ;
21842198 }
2185-
21862199 const query = parseQuery ( searchState . input . value . trim ( ) ) ;
21872200 let filterCrates = getFilterCrates ( ) ;
21882201
You can’t perform that action at this time.
0 commit comments