Skip to content

Commit

Permalink
If the current search result tab is empty, it picks the first non-emp…
Browse files Browse the repository at this point in the history
…ty one. If all are empty, the current one doesn't change.
  • Loading branch information
GuillaumeGomez committed Dec 30, 2020
1 parent 2acf6ee commit 3337767
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,21 @@ function defocusSearchBar() {
var ret_in_args = addTab(results.in_args, query, false);
var ret_returned = addTab(results.returned, query, false);

// Navigate to the relevant tab if the current tab is empty, like in case users search
// for "-> String". If they had selected another tab previously, they have to click on
// it again.
if ((currentTab === 0 && ret_others[1] === 0) ||
(currentTab === 1 && ret_in_args[1] === 0) ||
(currentTab === 2 && ret_returned[1] === 0)) {
if (ret_others[1] !== 0) {
currentTab = 0;
} else if (ret_in_args[1] !== 0) {
currentTab = 1;
} else if (ret_returned[1] !== 0) {
currentTab = 2;
}
}

var output = "<h1>Results for " + escape(query.query) +
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
"<div id=\"titles\">" +
Expand Down

0 comments on commit 3337767

Please sign in to comment.