From 4aa73968f07ea6921327314eecb30e7fc859e373 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Mar 2014 17:04:06 -0800 Subject: [PATCH] Converts keystrokes with alpha chars using shift e.g. cmd-shift-l would be converted to cmd-L --- spec/keymap-spec.coffee | 16 ++++++++++++++++ src/key-binding.coffee | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/keymap-spec.coffee b/spec/keymap-spec.coffee index b79783322..090da4bc8 100644 --- a/spec/keymap-spec.coffee +++ b/spec/keymap-spec.coffee @@ -254,6 +254,22 @@ describe "Keymap", -> it "favors the more specific complete match", -> describe ".bindKeys(name, selector, bindings)", -> + it "normalizes bindings that use shift with lower case alpha chars", -> + fooHandler = jasmine.createSpy('fooHandler') + fragment.on 'foo', fooHandler + keymap.bindKeys 'name', '*', 'ctrl-shift-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 bindings that use shift with upper case alpha chars", -> + fooHandler = jasmine.createSpy('fooHandler') + fragment.on 'foo', fooHandler + keymap.bindKeys 'name', '*', 'ctrl-shift-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 diff --git a/src/key-binding.coffee b/src/key-binding.coffee index 46b359858..1efaf8578 100644 --- a/src/key-binding.coffee +++ b/src/key-binding.coffee @@ -21,7 +21,14 @@ class KeyBinding keys = @parseKeystroke(keystroke) modifiers = keys[0...-1] modifiers.sort() - [modifiers..., _.last(keys)].join('-') + 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') + key = key.toUpperCase() + [modifiers..., key].join('-') + normalizedKeystroke.join(' ') @parseKeystroke: (keystroke) ->