Bug 1445776 - Add development restart shortcut to Browser Console. r=bgrins draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 14 Mar 2018 17:02:07 -0500
changeset 767739 0cfe2cba7bd0f570b88686b27a6c6a3cf69e6e09
parent 767665 0b13cc6f4c271ba56dc40cb7d9d9ff6f0f1de8e1
push id102676
push userbmo:jryans@gmail.com
push dateWed, 14 Mar 2018 23:12:33 +0000
reviewersbgrins
bugs1445776
milestone61.0a1
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
devtools/client/shared/key-shortcuts.js
devtools/client/webconsole/new-webconsole.js
--- 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();
         }
       });
     }
   },