diff options
| author | Jean-Luc Thumm <jeanlucthumm@gmail.com> | 2021-05-31 19:20:41 -0700 |
|---|---|---|
| committer | Jean-Luc Thumm <jeanlucthumm@gmail.com> | 2021-06-27 10:59:53 -0700 |
| commit | 68e3c49cdf1470ce78cd96a08877e09dabacdf93 (patch) | |
| tree | c13eb07e105a16715e68af695c5671b2afcc5264 | |
| parent | 49ba9361d87f5d58d54fdd164ef2128cd50ed4b4 (diff) | |
| download | rust-68e3c49cdf1470ce78cd96a08877e09dabacdf93.tar.gz rust-68e3c49cdf1470ce78cd96a08877e09dabacdf93.zip | |
Add go_to_first boolean query param to immeidately jump to the first search result
| -rw-r--r-- | src/librustdoc/html/static/search.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index 67be7b99155..0aebb0e9d65 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -1058,14 +1058,14 @@ window.initSearch = function(rawSearchIndex) { return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>"; } - function showResults(results) { + function showResults(results, go_to_first) { var search = searchState.outputElement(); - if (results.others.length === 1 + if (go_to_first || (results.others.length === 1 && getSettingValue("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 !== searchState.loadingText)) + && (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))) { var elem = document.createElement("a"); elem.href = results.others[0].href; @@ -1242,7 +1242,7 @@ window.initSearch = function(rawSearchIndex) { } var filterCrates = getFilterCrates(); - showResults(execSearch(query, index, filterCrates)); + showResults(execSearch(query, index, filterCrates), params.go_to_first); } function buildIndex(rawSearchIndex) { |
