Skip to content

Commit cb8a738

Browse files
committed
rustdoc: fix keyboard shortcuts bug in settings menu
This commit fixes the keyboard shorts code to call localStorage every time a key is pressed. This matters because you're supposed to be able to change a setting and have it immediately take effect.
1 parent cec6988 commit cb8a738

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/librustdoc/html/static/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ function loadCss(cssFileName) {
412412
window.hidePopoverMenus();
413413
}
414414

415-
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
416415
function handleShortcut(ev) {
417416
// Don't interfere with browser shortcuts
417+
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
418418
if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) {
419419
return;
420420
}

src/test/rustdoc-gui/settings.goml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ local-storage: {"rustdoc-disable-shortcuts": "false"}
121121
click: ".setting-line:last-child .toggle .label"
122122
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
123123

124+
// Make sure that "Disable keyboard shortcuts" actually took effect.
125+
press-key: "?"
126+
wait-for-css: ("#settings-menu .popover", {"display": "block"})
127+
128+
// Now turn keyboard shortcuts back on, and see if they work.
129+
click: ".setting-line:last-child .toggle .label"
130+
assert-local-storage: {"rustdoc-disable-shortcuts": "false"}
131+
press-key: "?"
132+
wait-for-css: ("#help-button .popover", {"display": "block"})
133+
assert-css: ("#settings-menu .popover", {"display": "none"})
134+
124135
// Now we go to the settings page to check that the CSS is loaded as expected.
125136
goto: file://|DOC_PATH|/settings.html
126137
wait-for: "#settings"

0 commit comments

Comments
 (0)