From e2649bc086f764859c94592b28237dab7d557493 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Mon, 23 Apr 2018 08:51:40 +0200 Subject: moebius#221: WebExtensions - commands API does not support shortcuts with space or numbers https://github.com/MoonchildProductions/moebius/pull/221 --- browser/components/webextensions/ext-commands.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'browser/components/webextensions/ext-commands.js') diff --git a/browser/components/webextensions/ext-commands.js b/browser/components/webextensions/ext-commands.js index 3f0bf8d1a..b6e7ab3d1 100644 --- a/browser/components/webextensions/ext-commands.js +++ b/browser/components/webextensions/ext-commands.js @@ -163,11 +163,12 @@ CommandList.prototype = { // The modifiers are the remaining elements. keyElement.setAttribute("modifiers", this.getModifiersAttribute(parts)); - if (/^[A-Z0-9]$/.test(chromeKey)) { + if (/^[A-Z]$/.test(chromeKey)) { // We use the key attribute for all single digits and characters. keyElement.setAttribute("key", chromeKey); } else { keyElement.setAttribute("keycode", this.getKeycodeAttribute(chromeKey)); + keyElement.setAttribute("event", "keydown"); } return keyElement; @@ -187,6 +188,9 @@ CommandList.prototype = { * @returns {string} The constructed value for the Key's 'keycode' attribute. */ getKeycodeAttribute(chromeKey) { + if (/[0-9]/.test(chromeKey)) { + return `VK_${chromeKey}`; + } return `VK${chromeKey.replace(/([A-Z])/g, "_$&").toUpperCase()}`; }, -- cgit v1.2.3