mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Refactor handling of numeric prefixes
Match prefix keys by doing a regex match against the keystroke string in the vim mode catch all binding.
This commit is contained in:
@@ -17,7 +17,11 @@ class VimMode
|
||||
@setupCommandMode()
|
||||
|
||||
setupCommandMode: ->
|
||||
atom.bindKeys '.command-mode', -> false
|
||||
atom.bindKeys '.command-mode', (e) ->
|
||||
if e.keystroke.match /\d/
|
||||
return 'command-mode:numeric-prefix'
|
||||
if e.keystroke.match /./
|
||||
return false
|
||||
|
||||
@bindCommandModeKeys
|
||||
'i': 'insert'
|
||||
@@ -30,10 +34,7 @@ class VimMode
|
||||
'delete-char': => new op.DeleteChar
|
||||
'move-left': => new op.MoveLeft
|
||||
'move-up': => new op.MoveUp
|
||||
|
||||
for i in [0..9]
|
||||
do (i) =>
|
||||
@registerCommand i, "numeric-prefix-#{i}", => new op.NumericPrefix(i)
|
||||
'numeric-prefix': (e) => @numericPrefix(e)
|
||||
|
||||
bindCommandModeKeys: (bindings) ->
|
||||
prefixedBindings = {}
|
||||
@@ -45,17 +46,10 @@ class VimMode
|
||||
handleCommands: (commands) ->
|
||||
_.each commands, (fn, commandName) =>
|
||||
eventName = "command-mode:#{commandName}"
|
||||
@editor.on eventName, =>
|
||||
possibleOperator = fn()
|
||||
@editor.on eventName, (e) =>
|
||||
possibleOperator = fn(e)
|
||||
@pushOperator(possibleOperator) if possibleOperator.execute?
|
||||
|
||||
registerCommand: (binding, commandName, fn)->
|
||||
eventName = "command-mode:#{commandName}"
|
||||
atom.bindKey '.command-mode', binding, eventName
|
||||
@editor.on eventName, =>
|
||||
possibleOperator = fn()
|
||||
@pushOperator(possibleOperator) if possibleOperator.execute?
|
||||
|
||||
activateInsertMode: ->
|
||||
@editor.removeClass('command-mode')
|
||||
@editor.addClass('insert-mode')
|
||||
@@ -64,6 +58,10 @@ class VimMode
|
||||
@editor.removeClass('insert-mode')
|
||||
@editor.addClass('command-mode')
|
||||
|
||||
numericPrefix: (e) ->
|
||||
num = parseInt(e.keyEvent.keystroke)
|
||||
new op.NumericPrefix(num)
|
||||
|
||||
pushOperator: (op) ->
|
||||
@opStack.push(op)
|
||||
@processOpStack()
|
||||
|
||||
Reference in New Issue
Block a user