diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2020-12-09 13:38:38 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-09 13:38:38 -0800 |
| commit | f74f3b2f37aaad4d78b85404ec1cc5e525c550d1 (patch) | |
| tree | 45deebfbb7cb6a0c2b79ff7f9684576c1c6492c7 | |
| parent | 8ffe7b6a81ec8c34814ac8fda4174a2f84033488 (diff) | |
| parent | 570de0a3be6e92840776dcb0b1706716f173c7ad (diff) | |
| download | rust-f74f3b2f37aaad4d78b85404ec1cc5e525c550d1.tar.gz rust-f74f3b2f37aaad4d78b85404ec1cc5e525c550d1.zip | |
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 https://github.com/rust-lang/rust/issues/65212 What took the longest time was to update the help popup in the end. r? `@Manishearth`
| -rw-r--r-- | src/librustdoc/html/static/main.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 0884351a9fd..a0ccb078c4a 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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"); @@ -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) { @@ -2898,11 +2896,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>"; |
