Skip to content

Commit 670acf7

Browse files
Rollup merge of #80382 - GuillaumeGomez:search-result-tab-picking, r=Nemo157,pickfire
Improve search result tab handling Fixes #80378. 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. It can be tested with "-> string" (where only the "returned elements" tab is not empty). r? `@jyn514`
2 parents 7d7b22d + 3337767 commit 670acf7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/librustdoc/html/static/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,21 @@ function defocusSearchBar() {
16501650
var ret_in_args = addTab(results.in_args, query, false);
16511651
var ret_returned = addTab(results.returned, query, false);
16521652

1653+
// Navigate to the relevant tab if the current tab is empty, like in case users search
1654+
// for "-> String". If they had selected another tab previously, they have to click on
1655+
// it again.
1656+
if ((currentTab === 0 && ret_others[1] === 0) ||
1657+
(currentTab === 1 && ret_in_args[1] === 0) ||
1658+
(currentTab === 2 && ret_returned[1] === 0)) {
1659+
if (ret_others[1] !== 0) {
1660+
currentTab = 0;
1661+
} else if (ret_in_args[1] !== 0) {
1662+
currentTab = 1;
1663+
} else if (ret_returned[1] !== 0) {
1664+
currentTab = 2;
1665+
}
1666+
}
1667+
16531668
var output = "<h1>Results for " + escape(query.query) +
16541669
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
16551670
"<div id=\"titles\">" +

0 commit comments

Comments
 (0)