Implement d3w

NumericPrefix now has a .select() method that calls select multiple
times on its operand. Editor.selectToPosition modified to extend
existing selections, and only create a new one if needed. This allows
repetition of a motion's select method to expand the selection.
This commit is contained in:
Nathan Sobo
2012-01-14 00:31:11 -08:00
parent 91cc9cc9a4
commit d1869516fd
3 changed files with 16 additions and 2 deletions

View File

@@ -68,6 +68,16 @@ describe "VimMode", ->
expect(editor.buffer.getText()).toBe "abefg"
expect(editor.getCursor()).toEqual {column: 2, row: 0}
editor.buffer.setText("one two three four")
editor.setCursor(column: 0, row: 0)
editor.trigger keydownEvent('d')
editor.trigger keydownEvent('3')
editor.trigger keydownEvent('w')
expect(editor.buffer.getText()).toBe "four"
expect(editor.getCursor()).toEqual {column: 0, row: 0}
describe "basic motion bindings", ->
beforeEach ->
editor.buffer.setText("12345\nabcde\nABCDE")

View File

@@ -59,8 +59,9 @@ class Editor extends Template
@aceEditor.navigateTo(row, column)
selectToPosition: (position) ->
{ row, column } = @getCursor()
@aceEditor.selection.setSelectionAnchor(row, column)
if @aceEditor.selection.isEmpty()
{ row, column } = @getCursor()
@aceEditor.selection.setSelectionAnchor(row, column)
@aceEditor.moveCursorToPosition(position)
delete: ->

View File

@@ -22,6 +22,9 @@ module.exports =
execute: (editor) ->
_.times @count, => @operatorToRepeat.execute(editor)
select: (editor) ->
_.times @count, => @operatorToRepeat.select(editor)
Delete: class
complete: null
motion: null