Skip to content

Commit 4913b92

Browse files
authored
Rollup merge of rust-lang#45281 - GuillaumeGomez:tab-selection, r=QuietMisdreavus
Save selected search tab Fixes rust-lang#45278. r? @rust-lang/docs
2 parents 0350c2f + 45bb03f commit 4913b92

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/librustdoc/html/static/main.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
"associatedconstant",
4040
"union"];
4141

42+
// On the search screen, so you remain on the last tab you opened.
43+
//
44+
// 0 for "Types/modules"
45+
// 1 for "As parameters"
46+
// 2 for "As return value"
47+
var currentTab = 0;
48+
4249
function hasClass(elem, className) {
4350
if (elem && className && elem.className) {
4451
var elemClass = elem.className;
@@ -758,7 +765,7 @@
758765

759766
var output = '';
760767
if (array.length > 0) {
761-
output = `<table class="search-results"${extraStyle}>`;
768+
output = '<table class="search-results"' + extraStyle + '>';
762769
var shown = [];
763770

764771
array.forEach(function(item) {
@@ -812,24 +819,32 @@
812819
});
813820
output += '</table>';
814821
} else {
815-
output = `<div class="search-failed"${extraStyle}>No results :(<br/>` +
822+
output = '<div class="search-failed"' + extraStyle + '>No results :(<br/>' +
816823
'Try on <a href="https://duckduckgo.com/?q=' +
817824
encodeURIComponent('rust ' + query.query) +
818825
'">DuckDuckGo</a>?</div>';
819826
}
820827
return output;
821828
}
822829

830+
function makeTabHeader(tabNb, text) {
831+
if (currentTab === tabNb) {
832+
return '<div class="selected">' + text + '</div>';
833+
}
834+
return '<div>' + text + '</div>';
835+
}
836+
823837
function showResults(results) {
824838
var output, query = getQuery();
825839

826840
currentResults = query.id;
827841
output = '<h1>Results for ' + escape(query.query) +
828842
(query.type ? ' (type: ' + escape(query.type) + ')' : '') + '</h1>' +
829843
'<div id="titles">' +
830-
'<div class="selected">Types/modules</div>' +
831-
'<div>As parameters</div>' +
832-
'<div>As return value</div></div><div id="results">';
844+
makeTabHeader(0, "Types/modules") +
845+
makeTabHeader(1, "As parameters") +
846+
makeTabHeader(2, "As return value") +
847+
'</div><div id="results">';
833848

834849
output += addTab(results['others'], query);
835850
output += addTab(results['in_args'], query, false);
@@ -1405,6 +1420,9 @@
14051420

14061421
// In the search display, allows to switch between tabs.
14071422
function printTab(nb) {
1423+
if (nb === 0 || nb === 1 || nb === 2) {
1424+
currentTab = nb;
1425+
}
14081426
var nb_copy = nb;
14091427
onEach(document.getElementById('titles').childNodes, function(elem) {
14101428
if (nb_copy === 0) {

0 commit comments

Comments
 (0)