Skip to content

Commit 68e3c49

Browse files
committed
Add go_to_first boolean query param to immeidately jump to the first search result
1 parent 49ba936 commit 68e3c49

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/librustdoc/html/static/search.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1058,14 +1058,14 @@ window.initSearch = function(rawSearchIndex) {
10581058
return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>";
10591059
}
10601060

1061-
function showResults(results) {
1061+
function showResults(results, go_to_first) {
10621062
var search = searchState.outputElement();
1063-
if (results.others.length === 1
1063+
if (go_to_first || (results.others.length === 1
10641064
&& getSettingValue("go-to-only-result") === "true"
10651065
// By default, the search DOM element is "empty" (meaning it has no children not
10661066
// text content). Once a search has been run, it won't be empty, even if you press
10671067
// ESC or empty the search input (which also "cancels" the search).
1068-
&& (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))
1068+
&& (!search.firstChild || search.firstChild.innerText !== searchState.loadingText)))
10691069
{
10701070
var elem = document.createElement("a");
10711071
elem.href = results.others[0].href;
@@ -1242,7 +1242,7 @@ window.initSearch = function(rawSearchIndex) {
12421242
}
12431243

12441244
var filterCrates = getFilterCrates();
1245-
showResults(execSearch(query, index, filterCrates));
1245+
showResults(execSearch(query, index, filterCrates), params.go_to_first);
12461246
}
12471247

12481248
function buildIndex(rawSearchIndex) {

0 commit comments

Comments
 (0)