From 649415d20a7ee2a496100b29e73eee4304c6fff0 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Fri, 13 Jan 2012 12:34:25 -0800 Subject: [PATCH] more :lipstick: --- src/atom/vim-mode.coffee | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/atom/vim-mode.coffee b/src/atom/vim-mode.coffee index 53677b556..5b0dc673c 100644 --- a/src/atom/vim-mode.coffee +++ b/src/atom/vim-mode.coffee @@ -19,15 +19,36 @@ class VimMode setupCommandMode: -> atom.bindKeys '.command-mode', -> false - @registerCommand 'i', 'insert', => @activateInsertMode() - @registerCommand 'x', 'delete-char', => new op.DeleteChar - @registerCommand 'h', 'move-left', => new op.MoveLeft - @registerCommand 'j', 'move-up', => new op.MoveUp + @bindCommandModeKeys + 'i': 'insert' + 'x': 'delete-char' + 'h': 'move-left' + 'j': 'move-up' + + @handleCommands + 'insert': => @activateInsertMode() + '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) + bindCommandModeKeys: (bindings) -> + prefixedBindings = {} + for pattern, commandName of bindings + prefixedBindings[pattern] = "command-mode:#{commandName}" + + atom.bindKeys ".command-mode", prefixedBindings + + handleCommands: (commands) -> + _.each commands, (fn, commandName) => + eventName = "command-mode:#{commandName}" + @editor.on eventName, => + possibleOperator = fn() + @pushOperator(possibleOperator) if possibleOperator.execute? + registerCommand: (binding, commandName, fn)-> eventName = "command-mode:#{commandName}" atom.bindKey '.command-mode', binding, eventName