Skip to content

Commit 1fef19a

Browse files
authored
Rollup merge of #98646 - notriddle:notriddle/main.js, r=GuillaumeGomez
rustdoc: fix bugs in main.js popover help and settings
2 parents 921e311 + ccea908 commit 1fef19a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,15 @@ 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
}
421421

422-
if (document.activeElement.tagName === "INPUT") {
422+
if (document.activeElement.tagName === "INPUT" &&
423+
document.activeElement.type !== "checkbox") {
423424
switch (getVirtualKey(ev)) {
424425
case "Escape":
425426
handleEscape(ev);
@@ -926,6 +927,7 @@ function loadCss(cssFileName) {
926927
function showHelp() {
927928
const menu = getHelpMenu(true);
928929
if (menu.style.display === "none") {
930+
window.hidePopoverMenus();
929931
menu.style.display = "";
930932
}
931933
}
@@ -939,6 +941,8 @@ function loadCss(cssFileName) {
939941
const shouldShowHelp = menu.style.display === "none";
940942
if (shouldShowHelp) {
941943
showHelp();
944+
} else {
945+
window.hidePopoverMenus();
942946
}
943947
});
944948

src/test/rustdoc-gui/pocket-menu.goml

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ click: "#help-button"
2424
assert-css: ("#help-button .popover", {"display": "block"})
2525
assert-css: ("#settings-menu .popover", {"display": "none"})
2626

27+
// Now verify that clicking the help menu again closes it.
28+
click: "#help-button"
29+
assert-css: ("#help-button .popover", {"display": "none"})
30+
assert-css: ("#settings-menu .popover", {"display": "none"})
31+
2732
// We check the borders color now:
2833

2934
// Ayu theme

src/test/rustdoc-gui/settings.goml

+14
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ 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: "Escape"
126+
press-key: "?"
127+
assert-false: "#help-button .popover"
128+
wait-for-css: ("#settings-menu .popover", {"display": "block"})
129+
130+
// Now turn keyboard shortcuts back on, and see if they work.
131+
click: ".setting-line:last-child .toggle .label"
132+
assert-local-storage: {"rustdoc-disable-shortcuts": "false"}
133+
press-key: "Escape"
134+
press-key: "?"
135+
wait-for-css: ("#help-button .popover", {"display": "block"})
136+
assert-css: ("#settings-menu .popover", {"display": "none"})
137+
124138
// Now we go to the settings page to check that the CSS is loaded as expected.
125139
goto: file://|DOC_PATH|/settings.html
126140
wait-for: "#settings"

0 commit comments

Comments
 (0)