@@ -1576,14 +1576,21 @@ function defocusSearchBar() {
1576
1576
}
1577
1577
1578
1578
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
+ {
1581
1587
var elem = document . createElement ( "a" ) ;
1582
1588
elem . href = results . others [ 0 ] . href ;
1583
1589
elem . style . display = "none" ;
1584
1590
// For firefox, we need the element to be in the DOM so it can be clicked.
1585
1591
document . body . appendChild ( elem ) ;
1586
1592
elem . click ( ) ;
1593
+ return ;
1587
1594
}
1588
1595
var query = getQuery ( search_input . value ) ;
1589
1596
@@ -1602,7 +1609,6 @@ function defocusSearchBar() {
1602
1609
"</div><div id=\"results\">" +
1603
1610
ret_others [ 0 ] + ret_in_args [ 0 ] + ret_returned [ 0 ] + "</div>" ;
1604
1611
1605
- var search = getSearchElement ( ) ;
1606
1612
search . innerHTML = output ;
1607
1613
showSearchResults ( search ) ;
1608
1614
var tds = search . getElementsByTagName ( "td" ) ;
@@ -2679,6 +2685,10 @@ function defocusSearchBar() {
2679
2685
}
2680
2686
}
2681
2687
2688
+ function getSearchLoadingText ( ) {
2689
+ return "Loading search results..." ;
2690
+ }
2691
+
2682
2692
if ( search_input ) {
2683
2693
search_input . onfocus = function ( ) {
2684
2694
putBackSearch ( this ) ;
@@ -2688,7 +2698,7 @@ function defocusSearchBar() {
2688
2698
var params = getQueryStringParams ( ) ;
2689
2699
if ( params && params . search ) {
2690
2700
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>";
2692
2702
showSearchResults ( search ) ;
2693
2703
}
2694
2704
0 commit comments