Skip to content
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

rustdoc: fix bugs in main.js popover help and settings #98646

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,15 @@ function loadCss(cssFileName) {
window.hidePopoverMenus();
}

const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
function handleShortcut(ev) {
// Don't interfere with browser shortcuts
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) {
return;
}

if (document.activeElement.tagName === "INPUT") {
if (document.activeElement.tagName === "INPUT" &&
document.activeElement.type !== "checkbox") {
switch (getVirtualKey(ev)) {
case "Escape":
handleEscape(ev);
Expand Down Expand Up @@ -926,6 +927,7 @@ function loadCss(cssFileName) {
function showHelp() {
const menu = getHelpMenu(true);
if (menu.style.display === "none") {
window.hidePopoverMenus();
menu.style.display = "";
}
}
Expand All @@ -939,6 +941,8 @@ function loadCss(cssFileName) {
const shouldShowHelp = menu.style.display === "none";
if (shouldShowHelp) {
showHelp();
} else {
window.hidePopoverMenus();
}
});

Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc-gui/pocket-menu.goml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ click: "#help-button"
assert-css: ("#help-button .popover", {"display": "block"})
assert-css: ("#settings-menu .popover", {"display": "none"})

// Now verify that clicking the help menu again closes it.
click: "#help-button"
assert-css: ("#help-button .popover", {"display": "none"})
assert-css: ("#settings-menu .popover", {"display": "none"})

// We check the borders color now:

// Ayu theme
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc-gui/settings.goml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ local-storage: {"rustdoc-disable-shortcuts": "false"}
click: ".setting-line:last-child .toggle .label"
assert-local-storage: {"rustdoc-disable-shortcuts": "true"}

// Make sure that "Disable keyboard shortcuts" actually took effect.
press-key: "Escape"
press-key: "?"
assert-false: "#help-button .popover"
wait-for-css: ("#settings-menu .popover", {"display": "block"})

// Now turn keyboard shortcuts back on, and see if they work.
click: ".setting-line:last-child .toggle .label"
assert-local-storage: {"rustdoc-disable-shortcuts": "false"}
press-key: "Escape"
press-key: "?"
wait-for-css: ("#help-button .popover", {"display": "block"})
assert-css: ("#settings-menu .popover", {"display": "none"})

// Now we go to the settings page to check that the CSS is loaded as expected.
goto: file://|DOC_PATH|/settings.html
wait-for: "#settings"
Expand Down