From 9e8b1fb6610fa779eda6a89595fa362f1ce01a2c Mon Sep 17 00:00:00 2001 From: probablycorey Date: Fri, 1 Nov 2013 11:02:46 -0700 Subject: [PATCH] Handle modifier keydown events When only a modifier is pressed it still triggers a keydown event. This normalizes the keystroke name for those events. --- src/keymap.coffee | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/keymap.coffee b/src/keymap.coffee index d64b1f082..89aa9f473 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -6,6 +6,8 @@ CSON = require 'season' BindingSet = require './binding-set' {Emitter} = require 'emissary' +Modifiers = ['alt', 'control', 'ctrl', 'shift', 'meta'] + # Internal: Associates keymaps with actions. # # Keymaps are defined in a CSON format. A typical keymap looks something like this: @@ -189,14 +191,14 @@ class Keymap key = event.originalEvent.keyIdentifier.toLowerCase() modifiers = [] - if event.altKey and key isnt 'alt' + if event.altKey and key not in Modifiers modifiers.push 'alt' - if event.ctrlKey and key isnt 'ctrl' + if event.ctrlKey and key not in Modifiers modifiers.push 'ctrl' - if event.metaKey and key isnt 'meta' + if event.metaKey and key not in Modifiers modifiers.push 'meta' - if event.shiftKey + if event.shiftKey and key not in Modifiers isNamedKey = key.length > 1 modifiers.push 'shift' if isNamedKey else