From 33377670773e07cc75a0a28424413ba74fc2bfb8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 26 Dec 2020 15:57:27 +0100 Subject: [PATCH] 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. --- src/librustdoc/html/static/main.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1de4b0016c567..6cecbf6643c6c 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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 = "

Results for " + escape(query.query) + (query.type ? " (type: " + escape(query.type) + ")" : "") + "

" + "
" +