From 031caec406377c93978a03007186034278b67726 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 19 Jan 2019 15:50:39 -0800 Subject: [PATCH] fix: fix Alt key in keyboard shortcuts (#902) fixes #896 --- src/routes/_utils/shortcuts.js | 1 + tests/unit/test-shortcuts.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/routes/_utils/shortcuts.js b/src/routes/_utils/shortcuts.js index a196b2de..702bc679 100644 --- a/src/routes/_utils/shortcuts.js +++ b/src/routes/_utils/shortcuts.js @@ -173,6 +173,7 @@ function unmapKeys (keyMap, keys, component) { function acceptShortcutEvent (event) { let { target } = event return !( + event.altKey || event.metaKey || event.ctrlKey || (event.shiftKey && event.key !== '?') || // '?' is a special case - it is allowed diff --git a/tests/unit/test-shortcuts.js b/tests/unit/test-shortcuts.js index 1b1ce28e..03710d4c 100644 --- a/tests/unit/test-shortcuts.js +++ b/tests/unit/test-shortcuts.js @@ -15,6 +15,7 @@ function KeyDownEvent (key) { this.metaKey = false this.ctrlKey = false this.shiftKey = false + this.altKey = false this.target = null } @@ -222,4 +223,15 @@ describe('test-shortcuts.js', function () { eventListener(new KeyDownEvent('a')) assert.ok(globalA.pressed()) }) + + it('ignores alt key', function () { + let component = new Component() + + addToShortcutScope('global', '1', component) + + let event = new KeyDownEvent('1') + event.altKey = true + eventListener(event) + assert.ok(component.notPressed()) + }) })