From 5af4bc7b50f31764e093b7415041366c52031768 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 14 Mar 2018 17:02:07 -0500 Subject: [PATCH] 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 --HG-- extra : rebase_source : a9864af63590c803a412959bf922c87859455448 --- devtools/client/shared/key-shortcuts.js | 12 ++++++++++-- devtools/client/webconsole/new-webconsole.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/devtools/client/shared/key-shortcuts.js b/devtools/client/shared/key-shortcuts.js index 7717e318efc2..5ede1037a8c5 100644 --- a/devtools/client/shared/key-shortcuts.js +++ b/devtools/client/shared/key-shortcuts.js @@ -135,8 +135,16 @@ KeyShortcuts.parseElectronKey = function(window, str) { } 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]; diff --git a/devtools/client/webconsole/new-webconsole.js b/devtools/client/webconsole/new-webconsole.js index 2052525ef4a7..5c695142d54f 100644 --- a/devtools/client/webconsole/new-webconsole.js +++ b/devtools/client/webconsole/new-webconsole.js @@ -253,6 +253,16 @@ NewWebConsoleFrame.prototype = { 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) {