From 06d44f0da17a3350ee4901dbd82e53da1bfcd05c Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Wed, 25 May 2016 08:31:06 -0700 Subject: [PATCH] Bug 1268450 - Fix 'Plus' key shortcut support. r=jryans --- devtools/client/shared/key-shortcuts.js | 9 +++++++-- .../client/shared/test/browser_key_shortcuts.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/devtools/client/shared/key-shortcuts.js b/devtools/client/shared/key-shortcuts.js index 8a03e3897008..6ee168671ff1 100644 --- a/devtools/client/shared/key-shortcuts.js +++ b/devtools/client/shared/key-shortcuts.js @@ -34,7 +34,6 @@ const ElectronKeysMapping = { "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", @@ -122,7 +121,13 @@ KeyShortcuts.parseElectronKey = function (window, str) { } } - 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) { diff --git a/devtools/client/shared/test/browser_key_shortcuts.js b/devtools/client/shared/test/browser_key_shortcuts.js index 0e9e191de7ad..ff78b10d2d36 100644 --- a/devtools/client/shared/test/browser_key_shortcuts.js +++ b/devtools/client/shared/test/browser_key_shortcuts.js @@ -9,6 +9,7 @@ add_task(function* () { }); yield testSimple(shortcuts); yield testNonLetterCharacter(shortcuts); + yield testPlusCharacter(shortcuts); yield testMixup(shortcuts); yield testLooseDigits(shortcuts); yield testExactModifiers(shortcuts); @@ -62,6 +63,20 @@ function testNonLetterCharacter(shortcuts) { 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");