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`
This commit is contained in:
Guillaume Gomez 2021-01-19 10:27:50 +01:00 committed by GitHub
commit 670acf7483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1650,6 +1650,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\">" +