Skip to content

Automatically jump to the first result when entering directly in the search form #84286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/librustdoc/html/static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,8 @@ window.initSearch = function(rawSearchIndex) {
var actives = [[], [], []];
// "current" is used to know which tab we're looking into.
var current = 0;
onEachLazy(document.getElementById("results").childNodes, function(e) {
var results = document.getElementById("results").childNodes;
onEachLazy(results, function(e) {
onEachLazy(e.getElementsByClassName("highlighted"), function(h_e) {
actives[current].push(h_e);
});
Expand All @@ -953,7 +954,6 @@ window.initSearch = function(rawSearchIndex) {
if (e.ctrlKey) { // Going through result tabs.
printTab(currentTab > 1 ? 0 : currentTab + 1);
} else if (!actives[currentTab].length) {
var results = document.getElementById("results").childNodes;
if (results.length > 0) {
var res = results[currentTab].getElementsByClassName("result");
if (res.length > 0) {
Expand All @@ -969,6 +969,14 @@ window.initSearch = function(rawSearchIndex) {
if (actives[currentTab].length) {
document.location.href =
actives[currentTab][0].getElementsByTagName("a")[0].href;
} else {
if (results.length > 0) {
var firstRes = results[0].getElementsByClassName("result");
if (firstRes.length > 0) {
document.location.href =
firstRes[0].getElementsByTagName("a")[0].href;
}
}
}
} else if (e.which === 16) { // shift
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
Expand Down