Can enter multi-digit numeric prefixes in command mode.

This commit is contained in:
Nathan Sobo
2012-01-13 14:49:25 -08:00
parent b4886bb6d6
commit 712475569d
3 changed files with 17 additions and 3 deletions

View File

@@ -64,7 +64,7 @@ describe "VimMode", ->
editor.trigger keydownEvent('j')
expect(editor.getCursor()).toEqual(column: 1, row: 0)
describe "numeric prefix binding", ->
describe "numeric prefix bindings", ->
it "repeats the following operation N times", ->
editor.buffer.setText("12345")
editor.setCursor(column: 1, row: 0)
@@ -74,6 +74,14 @@ describe "VimMode", ->
expect(editor.buffer.getText()).toBe '15'
editor.buffer.setText("123456789abc")
editor.setCursor(column: 0, row: 0)
editor.trigger keydownEvent('1')
editor.trigger keydownEvent('0')
editor.trigger keydownEvent('x')
expect(editor.buffer.getText()).toBe 'bc'
describe "insert-mode", ->
beforeEach ->
editor.trigger keydownEvent('i')

View File

@@ -14,6 +14,9 @@ module.exports =
isComplete: -> @complete
addDigit: (digit) ->
@count = @count * 10 + digit
execute: (editor) ->
_.times @count, => @operatorToRepeat.execute(editor)

View File

@@ -48,7 +48,7 @@ class VimMode
eventName = "command-mode:#{commandName}"
@editor.on eventName, (e) =>
possibleOperator = fn(e)
@pushOperator(possibleOperator) if possibleOperator.execute?
@pushOperator(possibleOperator) if possibleOperator?.execute
activateInsertMode: ->
@editor.removeClass('command-mode')
@@ -60,7 +60,10 @@ class VimMode
numericPrefix: (e) ->
num = parseInt(e.keyEvent.keystroke)
new op.NumericPrefix(num)
if @topOperator() instanceof op.NumericPrefix
@topOperator().addDigit(num)
else
@pushOperator(new op.NumericPrefix(num))
pushOperator: (op) ->
@opStack.push(op)