Bug 1445776 - Add development restart shortcut to Browser Console. r=bgrins
Adds the browser restart shortcut (Cmd / Ctrl + Alt + R) to the Browser Console
window. Only enabled for local development builds.
MozReview-Commit-ID: 2oTT55TYCx6
--- a/devtools/client/shared/key-shortcuts.js
+++ b/devtools/client/shared/key-shortcuts.js
@@ -130,18 +130,26 @@ KeyShortcuts.parseElectronKey = function
// Plus is a special case. It's a character key and shouldn't be matched
// against a keycode as it is only accessible via Shift/Capslock
if (key === "Plus") {
key = "+";
}
if (typeof key === "string" && key.length === 1) {
- // Match any single character
- shortcut.key = key.toLowerCase();
+ if (shortcut.alt) {
+ // When Alt is involved, some platforms (macOS) give different printable characters
+ // for the `key` value, like `®` for the key `R`. In this case, prefer matching by
+ // `keyCode` instead.
+ shortcut.keyCode = KeyCodes[`DOM_VK_${key.toUpperCase()}`];
+ shortcut.keyCodeString = key;
+ } else {
+ // Match any single character
+ shortcut.key = key.toLowerCase();
+ }
} else if (key in ElectronKeysMapping) {
// Maps the others manually to DOM API DOM_VK_*
key = ElectronKeysMapping[key];
shortcut.keyCode = KeyCodes[key];
// Used only to stringify the shortcut
shortcut.keyCodeString = key;
shortcut.key = key;
} else {
--- a/devtools/client/webconsole/new-webconsole.js
+++ b/devtools/client/webconsole/new-webconsole.js
@@ -248,16 +248,26 @@ NewWebConsoleFrame.prototype = {
shortcuts.on(clearShortcut, () => this.jsterm.clearOutput(true));
if (this.isBrowserConsole) {
shortcuts.on(l10n.getStr("webconsole.close.key"),
this.window.top.close.bind(this.window.top));
ZoomKeys.register(this.window);
+
+ if (!system.constants.MOZILLA_OFFICIAL) {
+ // In local builds, inject the "quick restart" shortcut.
+ // This script expects to have Services on the global and we haven't yet imported
+ // it into the window, so assign it.
+ this.window.Services = Services;
+ Services.scriptloader.loadSubScript(
+ "chrome://browser/content/browser-development-helpers.js", this.window);
+ shortcuts.on("CmdOrCtrl+Alt+R", this.window.DevelopmentHelpers.quickRestart);
+ }
} else if (Services.prefs.getBoolPref(PREF_SIDEBAR_ENABLED)) {
shortcuts.on("Esc", event => {
if (!this.jsterm.autocompletePopup || !this.jsterm.autocompletePopup.isOpen) {
this.newConsoleOutput.dispatchSidebarClose();
}
});
}
},