From 4560eff15436bd08374549fa8bcf49edafbf21ef Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 27 Dec 2011 16:30:04 -0800 Subject: [PATCH] Factor out `parseKeyPattern` from `keyEventMatchesPattern` method --- src/atom/window.coffee | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/atom/window.coffee b/src/atom/window.coffee index ebe94c1ec..5f2c90b20 100644 --- a/src/atom/window.coffee +++ b/src/atom/window.coffee @@ -38,6 +38,10 @@ windowAdditions = bindMenuItems: -> @bindMenuItem "File > Save", => @editor.save() + bindMenuItemAndKey: (path, pattern, action) -> + @bindMenuItem path, action + @bindKey pattern, action + bindMenuItem: (path, action) -> @menuItemActions[path] = action @@ -45,18 +49,22 @@ windowAdditions = @keyBindings[pattern] = action keyEventMatchesPattern: (event, pattern) -> - [modifiers..., key] = pattern.split '+' - patternModifiers = - ctrlKey: 'ctrl' in modifiers - altKey: 'alt' in modifiers - shiftKey: 'shift' in modifiers - metaKey: 'meta' in modifiers + keys = @parseKeyPattern pattern - patternModifiers.ctrlKey == event.ctrlKey and - patternModifiers.altKey == event.altKey and - patternModifiers.shiftKey == event.shiftKey and - patternModifiers.metaKey == event.metaKey and - event.which == key.toUpperCase().charCodeAt 0 + keys.ctrlKey == event.ctrlKey and + keys.altKey == event.altKey and + keys.shiftKey == event.shiftKey and + keys.metaKey == event.metaKey and + event.which == keys.key.toUpperCase().charCodeAt 0 + + parseKeyPattern: (pattern) -> + [modifiers..., key] = pattern.split '+' + + ctrlKey: 'ctrl' in modifiers + altKey: 'alt' in modifiers + shiftKey: 'shift' in modifiers + metaKey: 'meta' in modifiers + key: key registerEventHandlers: -> $(document).bind 'keydown', (event) =>