From 68e3c49cdf1470ce78cd96a08877e09dabacdf93 Mon Sep 17 00:00:00 2001 From: Jean-Luc Thumm Date: Mon, 31 May 2021 19:20:41 -0700 Subject: [PATCH] Add go_to_first boolean query param to immeidately jump to the first search result --- src/librustdoc/html/static/search.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index 67be7b991550..0aebb0e9d658 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -1058,14 +1058,14 @@ window.initSearch = function(rawSearchIndex) { return ""; } - 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) {