mirror of
https://github.com/atom/atom.git
synced 2026-02-05 20:25:04 -05:00
Keymap normalizes key patterns so modifier keys can be listed in a random order.
This commit is contained in:
@@ -15,6 +15,7 @@ class BindingSet
|
||||
if _.isFunction(mapOrFunction)
|
||||
mapOrFunction
|
||||
else
|
||||
mapOrFunction = @normalizeKeystrokePatterns(mapOrFunction)
|
||||
(event) =>
|
||||
for pattern, command of mapOrFunction
|
||||
return command if @eventMatchesPattern(event, pattern)
|
||||
@@ -23,3 +24,16 @@ class BindingSet
|
||||
eventMatchesPattern: (event, pattern) ->
|
||||
pattern = pattern.replace(/^<|>$/g, '')
|
||||
event.keystroke == pattern
|
||||
|
||||
normalizeKeystrokePatterns: (map) ->
|
||||
normalizedMap = {}
|
||||
for pattern, event of map
|
||||
normalizedMap[@normalizeKeystrokePattern(pattern)] = event
|
||||
normalizedMap
|
||||
|
||||
normalizeKeystrokePattern: (pattern) ->
|
||||
keys = pattern.split('-')
|
||||
modifiers = keys[0...-1]
|
||||
modifiers.sort()
|
||||
[modifiers..., _.last(keys)].join('-')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user