diff --git a/spec/atom/binding-set-spec.coffee b/spec/atom/binding-set-spec.coffee new file mode 100644 index 000000000..ed131a387 --- /dev/null +++ b/spec/atom/binding-set-spec.coffee @@ -0,0 +1,34 @@ +$ = require 'jquery' +_ = require 'underscore' +BindingSet = require 'binding-set' + +describe "BindingSet", -> + bindingSet = null + beforeEach -> + bindingSet = new BindingSet('*', 'x': 'foo') + + describe ".eventMatchesPattern(event, pattern)", -> + event = (key, attrs={}) -> + defaultAttrs = + ctrlKey: false + altKey: false + shiftKey: false + metaKey: false + + attrs.which = key.toUpperCase().charCodeAt(0) + $.Event 'keydown', _.extend({}, defaultAttrs, attrs) + + it "handles patterns with modifiers", -> + expect(bindingSet.eventMatchesPattern(event('q'), 'q')).toBeTruthy() + expect(bindingSet.eventMatchesPattern(event('0', altKey: true), '')).toBeTruthy() + expect(bindingSet.eventMatchesPattern(event('0', metaKey: true), '')).toBeTruthy() + expect(bindingSet.eventMatchesPattern(event('0', ctrlKey: true), '')).toBeTruthy() + expect(bindingSet.eventMatchesPattern(event('a', shiftKey: true), '')).toBeTruthy() + expect(bindingSet.eventMatchesPattern(event('a', shiftKey: true), 'A')).toBeTruthy() + expect(bindingSet.eventMatchesPattern(event('0', altKey: true, ctrlKey: true, metaKey: true, shiftKey: true), '')).toBeTruthy() + + # # negative examples + expect(bindingSet.eventMatchesPattern(event('a'), '')).toBeFalsy() + expect(bindingSet.eventMatchesPattern(event('a', shiftKey: true), 'a')).toBeFalsy() + expect(bindingSet.eventMatchesPattern(event('d'), 'k')).toBeFalsy() + diff --git a/src/atom/binding-set.coffee b/src/atom/binding-set.coffee index 39d331dcc..c248a97c4 100644 --- a/src/atom/binding-set.coffee +++ b/src/atom/binding-set.coffee @@ -30,7 +30,10 @@ class BindingSet pattern.which == event.which parseKeyPattern: (pattern) -> - [modifiers..., key] = pattern.split '+' + pattern = pattern.replace(/<|>/g, "") + [modifiers..., key] = pattern.split '-' + + modifiers.push 'shift' if key == key.toUpperCase() and key.toUpperCase() != key.toLowerCase() if @namedKeys[key] charCode = @namedKeys[key]