Skip to content

Commit

Permalink
Rollup merge of #75806 - GuillaumeGomez:prevent-automatic-page-change…
Browse files Browse the repository at this point in the history
…-history, r=pickfire

Prevent automatic page change when using history

Fixes #75774.
  • Loading branch information
Dylan-DPC authored Aug 26, 2020
2 parents a79f9af + 76bd5b3 commit 463fdf3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,14 +1576,21 @@ function defocusSearchBar() {
}

function showResults(results) {
if (results.others.length === 1 &&
getCurrentValue("rustdoc-go-to-only-result") === "true") {
var search = getSearchElement();
if (results.others.length === 1
&& getCurrentValue("rustdoc-go-to-only-result") === "true"
// By default, the search DOM element is "empty" (meaning it has no children not
// text content). Once a search has been run, it won't be empty, even if you press
// ESC or empty the search input (which also "cancels" the search).
&& (!search.firstChild || search.firstChild.innerText !== getSearchLoadingText()))
{
var elem = document.createElement("a");
elem.href = results.others[0].href;
elem.style.display = "none";
// For firefox, we need the element to be in the DOM so it can be clicked.
document.body.appendChild(elem);
elem.click();
return;
}
var query = getQuery(search_input.value);

Expand All @@ -1602,7 +1609,6 @@ function defocusSearchBar() {
"</div><div id=\"results\">" +
ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";

var search = getSearchElement();
search.innerHTML = output;
showSearchResults(search);
var tds = search.getElementsByTagName("td");
Expand Down Expand Up @@ -2679,6 +2685,10 @@ function defocusSearchBar() {
}
}

function getSearchLoadingText() {
return "Loading search results...";
}

if (search_input) {
search_input.onfocus = function() {
putBackSearch(this);
Expand All @@ -2688,7 +2698,7 @@ function defocusSearchBar() {
var params = getQueryStringParams();
if (params && params.search) {
var search = getSearchElement();
search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>";
search.innerHTML = "<h3 style=\"text-align: center;\">" + getSearchLoadingText() + "</h3>";
showSearchResults(search);
}

Expand Down

0 comments on commit 463fdf3

Please sign in to comment.