mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Move methods into KeyBinding class
This commit is contained in:
@@ -33,3 +33,16 @@ class KeyBinding
|
||||
@selector = selector.replace(/!important/g, '')
|
||||
@specificity = specificity(selector)
|
||||
@index = KeyBinding.currentIndex++
|
||||
|
||||
matches: (keystroke) ->
|
||||
multiKeystroke = /\s/.test keystroke
|
||||
if multiKeystroke
|
||||
keystroke == @keystroke
|
||||
else
|
||||
keystroke.split(' ')[0] == @keystroke.split(' ')[0]
|
||||
|
||||
compare: (keyBinding) ->
|
||||
if keyBinding.specificity == @specificity
|
||||
keyBinding.index - @index
|
||||
else
|
||||
keyBinding.specificity - @specificity
|
||||
|
||||
@@ -92,21 +92,12 @@ class Keymap
|
||||
|
||||
keyBindingsForKeystroke: (keystroke) ->
|
||||
keystroke = KeyBinding.normalizeKeystroke(keystroke)
|
||||
keyBindings = @keyBindings.filter (keyBinding) -> keyBinding.matches(keystroke)
|
||||
|
||||
keyBindings = @getKeyBindings().filter (keyBinding) ->
|
||||
multiKeystroke = /\s/.test keystroke
|
||||
if multiKeystroke
|
||||
keystroke == keyBinding.keystroke
|
||||
else
|
||||
keystroke.split(' ')[0] == keyBinding.keystroke.split(' ')[0]
|
||||
|
||||
keyBindingsMatchingElement: (element, keyBindings=@getKeyBindings()) ->
|
||||
keyBindings = keyBindings.filter ({selector}) -> $(element).closest(selector).length > 0
|
||||
keyBindings.sort (a, b) ->
|
||||
if b.specificity == a.specificity
|
||||
b.index - a.index
|
||||
else
|
||||
b.specificity - a.specificity
|
||||
keyBindings.sort (a, b) -> a.compare(b)
|
||||
|
||||
triggerCommandEvent: (element, commandName) ->
|
||||
commandEvent = $.Event(commandName)
|
||||
|
||||
Reference in New Issue
Block a user