diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-08-27 01:14:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-27 01:14:08 +0200 |
| commit | 463fdf3e042c7429f2d85d2cdc042463d2cd7720 (patch) | |
| tree | 66350d5585ab1f1f0b1a29a54d3b789d5f3834d1 /src/librustdoc | |
| parent | a79f9af290ad69cd4fb32a3e1b5e610a21262717 (diff) | |
| parent | 76bd5b3852d39e624999e6f3dd16cd2b02657333 (diff) | |
| download | rust-463fdf3e042c7429f2d85d2cdc042463d2cd7720.tar.gz rust-463fdf3e042c7429f2d85d2cdc042463d2cd7720.zip | |
Rollup merge of #75806 - GuillaumeGomez:prevent-automatic-page-change-history, r=pickfire
Prevent automatic page change when using history Fixes #75774.
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/html/static/main.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 462a696dee6..57c8d5bff76 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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); @@ -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"); @@ -2679,6 +2685,10 @@ function defocusSearchBar() { } } + function getSearchLoadingText() { + return "Loading search results..."; + } + if (search_input) { search_input.onfocus = function() { putBackSearch(this); @@ -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); } |
