From a3cd47760de5ae6169fdd5b0145d15511fbd1c85 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Thu, 12 May 2016 03:07:56 -0700 Subject: [PATCH] Bug 1268441 - Fix support of all non-letter characters. r=bgrins --- devtools/client/shared/key-shortcuts.js | 2 +- .../client/shared/test/browser_key_shortcuts.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/devtools/client/shared/key-shortcuts.js b/devtools/client/shared/key-shortcuts.js index 418f6f36883c..384620d45e39 100644 --- a/devtools/client/shared/key-shortcuts.js +++ b/devtools/client/shared/key-shortcuts.js @@ -122,7 +122,7 @@ KeyShortcuts.parseElectronKey = function (window, str) { } } - if (key.match(/^\w$/)) { + 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 044cb94c78a6..73aaf938db13 100644 --- a/devtools/client/shared/test/browser_key_shortcuts.js +++ b/devtools/client/shared/test/browser_key_shortcuts.js @@ -8,6 +8,7 @@ add_task(function* () { window }); yield testSimple(shortcuts); + yield testNonLetterCharacter(shortcuts); yield testMixup(shortcuts); yield testExactModifiers(shortcuts); yield testLooseShiftModifier(shortcuts); @@ -38,7 +39,6 @@ function once(shortcuts, key, listener) { function testSimple(shortcuts) { info("Test simple key shortcuts"); - let called = false; let onKey = once(shortcuts, "0", (key, event) => { is(event.key, "0"); @@ -50,6 +50,17 @@ function testSimple(shortcuts) { yield onKey; } +function testNonLetterCharacter(shortcuts) { + info("Test non-naive character key shortcuts"); + + let onKey = once(shortcuts, "[", (key, event) => { + is(event.key, "["); + }); + + EventUtils.synthesizeKey("[", {}, window); + yield onKey; +} + // Test they listeners are not mixed up between shortcuts function testMixup(shortcuts) { info("Test possible listener mixup");