Skip to content

Commit f74f3b2

Browse files
authored
Rollup merge of #79862 - GuillaumeGomez:tab-lock, r=Manishearth
Remove tab-lock and replace it with ctrl+up/down arrows to switch between search result tabs Fixes #65212 What took the longest time was to update the help popup in the end. r? `@Manishearth`
2 parents 8ffe7b6 + 570de0a commit f74f3b2

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/librustdoc/html/static/main.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -1469,16 +1469,21 @@ function defocusSearchBar() {
14691469
});
14701470

14711471
if (e.which === 38) { // up
1472-
if (!actives[currentTab].length ||
1473-
!actives[currentTab][0].previousElementSibling) {
1474-
return;
1472+
if (e.ctrlKey) { // Going through result tabs.
1473+
printTab(currentTab > 0 ? currentTab - 1 : 2);
1474+
} else {
1475+
if (!actives[currentTab].length ||
1476+
!actives[currentTab][0].previousElementSibling) {
1477+
return;
1478+
}
1479+
addClass(actives[currentTab][0].previousElementSibling, "highlighted");
1480+
removeClass(actives[currentTab][0], "highlighted");
14751481
}
1476-
1477-
addClass(actives[currentTab][0].previousElementSibling, "highlighted");
1478-
removeClass(actives[currentTab][0], "highlighted");
14791482
e.preventDefault();
14801483
} else if (e.which === 40) { // down
1481-
if (!actives[currentTab].length) {
1484+
if (e.ctrlKey) { // Going through result tabs.
1485+
printTab(currentTab > 1 ? 0 : currentTab + 1);
1486+
} else if (!actives[currentTab].length) {
14821487
var results = document.getElementById("results").childNodes;
14831488
if (results.length > 0) {
14841489
var res = results[currentTab].getElementsByClassName("result");
@@ -1496,13 +1501,6 @@ function defocusSearchBar() {
14961501
document.location.href =
14971502
actives[currentTab][0].getElementsByTagName("a")[0].href;
14981503
}
1499-
} else if (e.which === 9) { // tab
1500-
if (e.shiftKey) {
1501-
printTab(currentTab > 0 ? currentTab - 1 : 2);
1502-
} else {
1503-
printTab(currentTab > 1 ? 0 : currentTab + 1);
1504-
}
1505-
e.preventDefault();
15061504
} else if (e.which === 16) { // shift
15071505
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
15081506
} else if (actives[currentTab].length > 0) {
@@ -2898,11 +2896,14 @@ function defocusSearchBar() {
28982896
["T", "Focus the theme picker menu"],
28992897
["↑", "Move up in search results"],
29002898
["↓", "Move down in search results"],
2901-
["", "Switch tab"],
2899+
["ctrl + ↑ / ↓", "Switch result tab"],
29022900
["⏎", "Go to active search result"],
29032901
["+", "Expand all sections"],
29042902
["-", "Collapse all sections"],
2905-
].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2903+
].map(x => "<dt>" +
2904+
x[0].split(" ")
2905+
.map((y, index) => (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : y)
2906+
.join("") + "</dt><dd>" + x[1] + "</dd>").join("");
29062907
var div_shortcuts = document.createElement("div");
29072908
addClass(div_shortcuts, "shortcuts");
29082909
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";

0 commit comments

Comments
 (0)