Skip to content

Remove tab-lock and replace it with ctrl+up/down arrows to switch between search result tabs #79862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,16 +1469,21 @@ function defocusSearchBar() {
});

if (e.which === 38) { // up
if (!actives[currentTab].length ||
!actives[currentTab][0].previousElementSibling) {
return;
if (e.ctrlKey) { // Going through result tabs.
printTab(currentTab > 0 ? currentTab - 1 : 2);
} else {
if (!actives[currentTab].length ||
!actives[currentTab][0].previousElementSibling) {
return;
}
addClass(actives[currentTab][0].previousElementSibling, "highlighted");
removeClass(actives[currentTab][0], "highlighted");
}

addClass(actives[currentTab][0].previousElementSibling, "highlighted");
removeClass(actives[currentTab][0], "highlighted");
e.preventDefault();
} else if (e.which === 40) { // down
if (!actives[currentTab].length) {
if (e.ctrlKey) { // Going through result tabs.
printTab(currentTab > 1 ? 0 : currentTab + 1);
} else if (!actives[currentTab].length) {
var results = document.getElementById("results").childNodes;
if (results.length > 0) {
var res = results[currentTab].getElementsByClassName("result");
Expand All @@ -1496,13 +1501,6 @@ function defocusSearchBar() {
document.location.href =
actives[currentTab][0].getElementsByTagName("a")[0].href;
}
} else if (e.which === 9) { // tab
if (e.shiftKey) {
printTab(currentTab > 0 ? currentTab - 1 : 2);
} else {
printTab(currentTab > 1 ? 0 : currentTab + 1);
}
e.preventDefault();
} else if (e.which === 16) { // shift
// Does nothing, it's just to avoid losing "focus" on the highlighted element.
} else if (actives[currentTab].length > 0) {
Expand Down Expand Up @@ -2879,11 +2877,14 @@ function defocusSearchBar() {
["T", "Focus the theme picker menu"],
["↑", "Move up in search results"],
["↓", "Move down in search results"],
["", "Switch tab"],
["ctrl + ↑ / ↓", "Switch result tab"],
["⏎", "Go to active search result"],
["+", "Expand all sections"],
["-", "Collapse all sections"],
].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
].map(x => "<dt>" +
x[0].split(" ")
.map((y, index) => (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : y)
.join("") + "</dt><dd>" + x[1] + "</dd>").join("");
var div_shortcuts = document.createElement("div");
addClass(div_shortcuts, "shortcuts");
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
Expand Down