Bug 1268450 - Fix 'Plus' key shortcut support. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 25 May 2016 08:31:06 -0700
changeset 340021 df627da479f868c9704d7ac0b1c6aa76fb298150
parent 340020 550359b138498145d266ac265d4c16eb6ae73c15
child 340022 8d0aadfe7da782d415363880008b4ca027686137
child 340075 0183f1bb4655f70a64262749b9991ba7ef0cda8b
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1268450
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1268450 - Fix 'Plus' key shortcut support. r=jryans
devtools/client/shared/key-shortcuts.js
devtools/client/shared/test/browser_key_shortcuts.js
--- a/devtools/client/shared/key-shortcuts.js
+++ b/devtools/client/shared/key-shortcuts.js
@@ -29,17 +29,16 @@ const ElectronKeysMapping = {
   "F17": "DOM_VK_F17",
   "F18": "DOM_VK_F18",
   "F19": "DOM_VK_F19",
   "F20": "DOM_VK_F20",
   "F21": "DOM_VK_F21",
   "F22": "DOM_VK_F22",
   "F23": "DOM_VK_F23",
   "F24": "DOM_VK_F24",
-  "Plus": "DOM_VK_PLUS",
   "Space": "DOM_VK_SPACE",
   "Backspace": "DOM_VK_BACK_SPACE",
   "Delete": "DOM_VK_DELETE",
   "Insert": "DOM_VK_INSERT",
   "Return": "DOM_VK_RETURN",
   "Enter": "DOM_VK_RETURN",
   "Up": "DOM_VK_UP",
   "Down": "DOM_VK_DOWN",
@@ -117,17 +116,23 @@ KeyShortcuts.parseElectronKey = function
       shortcut.ctrl = true;
     } else if (mod === "Shift") {
       shortcut.shift = true;
     } else {
       throw new Error("Unsupported modifier: " + mod);
     }
   }
 
-  if (typeof (key) === "string" && key.length === 1) {
+  // 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();
   } else if (key in ElectronKeysMapping) {
     // Maps the others manually to DOM API DOM_VK_*
     key = ElectronKeysMapping[key];
     shortcut.keyCode = window.KeyboardEvent[key];
     // Used only to stringify the shortcut
     shortcut.keyCodeString = key;
--- a/devtools/client/shared/test/browser_key_shortcuts.js
+++ b/devtools/client/shared/test/browser_key_shortcuts.js
@@ -4,16 +4,17 @@
 var isOSX = Services.appinfo.OS === "Darwin";
 
 add_task(function* () {
   let shortcuts = new KeyShortcuts({
     window
   });
   yield testSimple(shortcuts);
   yield testNonLetterCharacter(shortcuts);
+  yield testPlusCharacter(shortcuts);
   yield testMixup(shortcuts);
   yield testLooseDigits(shortcuts);
   yield testExactModifiers(shortcuts);
   yield testLooseShiftModifier(shortcuts);
   yield testStrictLetterShiftModifier(shortcuts);
   yield testAltModifier(shortcuts);
   yield testCommandOrControlModifier(shortcuts);
   yield testCtrlModifier(shortcuts);
@@ -57,16 +58,30 @@ function testNonLetterCharacter(shortcut
   let onKey = once(shortcuts, "[", (key, event) => {
     is(event.key, "[");
   });
 
   EventUtils.synthesizeKey("[", {}, window);
   yield onKey;
 }
 
+// Plus is special. It's keycode is the one for "=". That's because it requires
+// shift to be pressed and is behind "=" key. So it should be considered as a
+// character key
+function testPlusCharacter(shortcuts) {
+  info("Test 'Plus' key shortcuts");
+
+  let onKey = once(shortcuts, "Plus", (key, event) => {
+    is(event.key, "+");
+  });
+
+  EventUtils.synthesizeKey("+", { keyCode: 61, shiftKey: true }, window);
+  yield onKey;
+}
+
 // Test they listeners are not mixed up between shortcuts
 function testMixup(shortcuts) {
   info("Test possible listener mixup");
 
   let hitFirst = false, hitSecond = false;
   let onFirstKey = once(shortcuts, "0", (key, event) => {
     is(event.key, "0");
     hitFirst = true;