From 45bb03f60c38be48b6ec06c95a4c6fa9b5c6ffba Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 14 Oct 2017 16:31:48 +0200 Subject: [PATCH] Save selected search tab --- src/librustdoc/html/static/main.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index bccad6c89dc..8c260132902 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -39,6 +39,13 @@ "associatedconstant", "union"]; + // On the search screen, so you remain on the last tab you opened. + // + // 0 for "Types/modules" + // 1 for "As parameters" + // 2 for "As return value" + var currentTab = 0; + function hasClass(elem, className) { if (elem && className && elem.className) { var elemClass = elem.className; @@ -747,7 +754,7 @@ var output = ''; if (array.length > 0) { - output = ``; + output = '
'; var shown = []; array.forEach(function(item) { @@ -801,7 +808,7 @@ }); output += '
'; } else { - output = `
No results :(
` + + output = '
No results :(
' + 'Try on DuckDuckGo?
'; @@ -809,6 +816,13 @@ return output; } + function makeTabHeader(tabNb, text) { + if (currentTab === tabNb) { + return '
' + text + '
'; + } + return '
' + text + '
'; + } + function showResults(results) { var output, query = getQuery(); @@ -816,9 +830,10 @@ output = '

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

' + '
' + - '
Types/modules
' + - '
As parameters
' + - '
As return value
'; + makeTabHeader(0, "Types/modules") + + makeTabHeader(1, "As parameters") + + makeTabHeader(2, "As return value") + + '
'; output += addTab(results['others'], query); output += addTab(results['in_args'], query, false); @@ -1394,6 +1409,9 @@ // In the search display, allows to switch between tabs. function printTab(nb) { + if (nb === 0 || nb === 1 || nb === 2) { + currentTab = nb; + } var nb_copy = nb; onEach(document.getElementById('titles').childNodes, function(elem) { if (nb_copy === 0) {