Move methods into KeyBinding class

This commit is contained in:
probablycorey
2013-11-15 14:05:35 -08:00
parent 02f40688e2
commit 98b509441c
2 changed files with 15 additions and 11 deletions

View File

@@ -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

View File

@@ -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)