diff --git a/spec/keymap-spec.coffee b/spec/keymap-spec.coffee index 4639dcddc..4476693c1 100644 --- a/spec/keymap-spec.coffee +++ b/spec/keymap-spec.coffee @@ -270,6 +270,14 @@ describe "Keymap", -> expect(result).toBe(false) expect(fooHandler).toHaveBeenCalled() + it "normalizes bindings that use an upper case alpha char without shift", -> + fooHandler = jasmine.createSpy('fooHandler') + fragment.on 'foo', fooHandler + keymap.bindKeys 'name', '*', 'ctrl-L': 'foo' + result = keymap.handleKeyEvent(keydownEvent('l', ctrlKey: true, altKey: false, shiftKey: true, target: fragment[0])) + expect(result).toBe(false) + expect(fooHandler).toHaveBeenCalled() + it "normalizes the key patterns in the hash to put the modifiers in alphabetical order", -> fooHandler = jasmine.createSpy('fooHandler') fragment.on 'foo', fooHandler @@ -322,7 +330,7 @@ describe "Keymap", -> describe "when shift is pressed when a non-modifer key", -> it "returns a string that identifies the key pressed", -> - expect(keymap.keystrokeStringForEvent(keydownEvent('A', shiftKey: true))).toBe 'A' + expect(keymap.keystrokeStringForEvent(keydownEvent('A', shiftKey: true))).toBe 'shift-A' expect(keymap.keystrokeStringForEvent(keydownEvent('{', shiftKey: true))).toBe '{' expect(keymap.keystrokeStringForEvent(keydownEvent('left', shiftKey: true))).toBe 'shift-left' expect(keymap.keystrokeStringForEvent(keydownEvent('Left', shiftKey: true))).toBe 'shift-left' diff --git a/src/key-binding.coffee b/src/key-binding.coffee index 1efaf8578..3c2422288 100644 --- a/src/key-binding.coffee +++ b/src/key-binding.coffee @@ -23,9 +23,9 @@ class KeyBinding modifiers.sort() key = _.last(keys) - # Uppercase alpha chars if the shift modifer is pressed - if 'shift' in modifiers and /^[a-z]$/i.test(key) - modifiers = _.without(modifiers, 'shift') + # Add the shift modifier if the key is an uppercased alpha char + if /^[A-Z]$/.test(key) or 'shift' in modifiers + modifiers.push 'shift' unless 'shift' in modifiers key = key.toUpperCase() [modifiers..., key].join('-') diff --git a/src/keymap.coffee b/src/keymap.coffee index 2b47b3053..4a8d72701 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -99,10 +99,12 @@ class Keymap modifiers.push 'cmd' if event.ctrlKey and key not in Modifiers modifiers.push 'ctrl' - if event.shiftKey and key not in Modifiers - isNamedKey = key.length > 1 - modifiers.push 'shift' if isNamedKey + # Don't push the shift modifier on single letter non-alpha keys (e.g. { or ') + modifiers.push 'shift' unless /^[^a-z]$/i.test(key) + + if 'shift' in modifiers and /^[a-z]$/i.test(key) + key = key.toUpperCase() else key = key.toLowerCase()