Skip to content

Commit 3337767

Browse files
If the current search result tab is empty, it picks the first non-empty one. If all are empty, the current one doesn't change.
1 parent 2acf6ee commit 3337767

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/librustdoc/html/static/main.js

+15
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,21 @@ function defocusSearchBar() {
16641664
var ret_in_args = addTab(results.in_args, query, false);
16651665
var ret_returned = addTab(results.returned, query, false);
16661666

1667+
// Navigate to the relevant tab if the current tab is empty, like in case users search
1668+
// for "-> String". If they had selected another tab previously, they have to click on
1669+
// it again.
1670+
if ((currentTab === 0 && ret_others[1] === 0) ||
1671+
(currentTab === 1 && ret_in_args[1] === 0) ||
1672+
(currentTab === 2 && ret_returned[1] === 0)) {
1673+
if (ret_others[1] !== 0) {
1674+
currentTab = 0;
1675+
} else if (ret_in_args[1] !== 0) {
1676+
currentTab = 1;
1677+
} else if (ret_returned[1] !== 0) {
1678+
currentTab = 2;
1679+
}
1680+
}
1681+
16671682
var output = "<h1>Results for " + escape(query.query) +
16681683
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
16691684
"<div id=\"titles\">" +

0 commit comments

Comments
 (0)