Skip to content

Commit f442326

Browse files
Save current highlighted item in search tab
1 parent 45bb03f commit f442326

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/librustdoc/html/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ r##"<!DOCTYPE html>
101101
<dd>Move up in search results</dd>
102102
<dt>&rarrb;</dt>
103103
<dd>Move down in search results</dd>
104+
<dt>↹</dt>
105+
<dd>Switch tab</dd>
104106
<dt>&#9166;</dt>
105107
<dd>Go to active search result</dd>
106108
<dt>+</dt>

src/librustdoc/html/static/main.js

+31-16
Original file line numberDiff line numberDiff line change
@@ -701,41 +701,56 @@
701701
});
702702

703703
var search_input = document.getElementsByClassName('search-input')[0];
704-
search_input.onkeydown = null;
705704
search_input.onkeydown = function(e) {
706-
var actives = [];
705+
// "actives" references the currently highlighted item in each search tab.
706+
// Each array in "actives" represents a tab.
707+
var actives = [[], [], []];
708+
// "current" is used to know which tab we're looking into.
709+
var current = 0;
707710
onEach(document.getElementsByClassName('search-results'), function(e) {
708-
onEach(document.getElementsByClassName('highlighted'), function(e) {
709-
actives.push(e);
711+
onEach(e.getElementsByClassName('highlighted'), function(e) {
712+
actives[current].push(e);
710713
});
714+
current += 1;
711715
});
712716

713717
if (e.which === 38) { // up
714-
if (!actives.length || !actives[0].previousElementSibling) {
718+
if (!actives[currentTab].length ||
719+
!actives[currentTab][0].previousElementSibling) {
715720
return;
716721
}
717722

718-
addClass(actives[0].previousElementSibling, 'highlighted');
719-
removeClass(actives[0], 'highlighted');
723+
addClass(actives[currentTab][0].previousElementSibling, 'highlighted');
724+
removeClass(actives[currentTab][0], 'highlighted');
720725
} else if (e.which === 40) { // down
721-
if (!actives.length) {
726+
if (!actives[currentTab].length) {
722727
var results = document.getElementsByClassName('search-results');
723728
if (results.length > 0) {
724-
var res = results[0].getElementsByClassName('result');
729+
var res = results[currentTab].getElementsByClassName('result');
725730
if (res.length > 0) {
726731
addClass(res[0], 'highlighted');
727732
}
728733
}
729-
} else if (actives[0].nextElementSibling) {
730-
addClass(actives[0].nextElementSibling, 'highlighted');
731-
removeClass(actives[0], 'highlighted');
734+
} else if (actives[currentTab][0].nextElementSibling) {
735+
addClass(actives[currentTab][0].nextElementSibling, 'highlighted');
736+
removeClass(actives[currentTab][0], 'highlighted');
732737
}
733738
} else if (e.which === 13) { // return
734-
if (actives.length) {
735-
document.location.href = actives[0].getElementsByTagName('a')[0].href;
739+
if (actives[currentTab].length) {
740+
document.location.href =
741+
actives[currentTab][0].getElementsByTagName('a')[0].href;
736742
}
737-
} else if (actives.length > 0) {
738-
removeClass(actives[0], 'highlighted');
743+
} else if (e.which === 9) { // tab
744+
if (e.shiftKey) {
745+
printTab(currentTab > 0 ? currentTab - 1 : 2);
746+
} else {
747+
printTab(currentTab > 1 ? 0 : currentTab + 1);
748+
}
749+
e.preventDefault();
750+
} else if (e.which === 16) { // shift
751+
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
752+
} else if (actives[currentTab].length > 0) {
753+
removeClass(actives[currentTab][0], 'highlighted');
739754
}
740755
};
741756
}

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ body.blur > :not(#help) {
552552
flex: 0 0 auto;
553553
box-shadow: 0 0 6px rgba(0,0,0,.2);
554554
width: 550px;
555-
height: 330px;
555+
height: 354px;
556556
border: 1px solid;
557557
}
558558
#help dt {

0 commit comments

Comments
 (0)