@@ -1576,14 +1576,21 @@ function defocusSearchBar() {
15761576 }
15771577
15781578 function showResults ( results ) {
1579- if ( results . others . length === 1 &&
1580- getCurrentValue ( "rustdoc-go-to-only-result" ) === "true" ) {
1579+ var search = getSearchElement ( ) ;
1580+ if ( results . others . length === 1
1581+ && getCurrentValue ( "rustdoc-go-to-only-result" ) === "true"
1582+ // By default, the search DOM element is "empty" (meaning it has no children not
1583+ // text content). Once a search has been run, it won't be empty, even if you press
1584+ // ESC or empty the search input (which also "cancels" the search).
1585+ && ( ! search . firstChild || search . firstChild . innerText !== getSearchLoadingText ( ) ) )
1586+ {
15811587 var elem = document . createElement ( "a" ) ;
15821588 elem . href = results . others [ 0 ] . href ;
15831589 elem . style . display = "none" ;
15841590 // For firefox, we need the element to be in the DOM so it can be clicked.
15851591 document . body . appendChild ( elem ) ;
15861592 elem . click ( ) ;
1593+ return ;
15871594 }
15881595 var query = getQuery ( search_input . value ) ;
15891596
@@ -1602,7 +1609,6 @@ function defocusSearchBar() {
16021609 "</div><div id=\"results\">" +
16031610 ret_others [ 0 ] + ret_in_args [ 0 ] + ret_returned [ 0 ] + "</div>" ;
16041611
1605- var search = getSearchElement ( ) ;
16061612 search . innerHTML = output ;
16071613 showSearchResults ( search ) ;
16081614 var tds = search . getElementsByTagName ( "td" ) ;
@@ -2679,6 +2685,10 @@ function defocusSearchBar() {
26792685 }
26802686 }
26812687
2688+ function getSearchLoadingText ( ) {
2689+ return "Loading search results..." ;
2690+ }
2691+
26822692 if ( search_input ) {
26832693 search_input . onfocus = function ( ) {
26842694 putBackSearch ( this ) ;
@@ -2688,7 +2698,7 @@ function defocusSearchBar() {
26882698 var params = getQueryStringParams ( ) ;
26892699 if ( params && params . search ) {
26902700 var search = getSearchElement ( ) ;
2691- search . innerHTML = "<h3 style=\"text-align: center;\">Loading search results... </h3>" ;
2701+ search . innerHTML = "<h3 style=\"text-align: center;\">" + getSearchLoadingText ( ) + " </h3>";
26922702 showSearchResults ( search ) ;
26932703 }
26942704
0 commit comments