about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-01-19 10:27:50 +0100
committerGitHub <noreply@github.com>2021-01-19 10:27:50 +0100
commit670acf7483ac6e1a22186c1f40086b18ee0ed71e (patch)
tree022fa6e898a2f87f8b3a6aba12a096ab5b97acaa
parent7d7b22d78fa71cf18109dc9d186611f2ddf60d8e (diff)
parent33377670773e07cc75a0a28424413ba74fc2bfb8 (diff)
downloadrust-670acf7483ac6e1a22186c1f40086b18ee0ed71e.tar.gz
rust-670acf7483ac6e1a22186c1f40086b18ee0ed71e.zip
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`
-rw-r--r--src/librustdoc/html/static/main.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 3ffb72ba3ee..035de64c7cc 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -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\">" +