Implement dw (delete to beginning of next word)

The w motion has a .select() method. When d composes with a motion it
calls select() on it and then deletes the selected text.
This commit is contained in:
Nathan Sobo
2012-01-14 00:10:34 -08:00
parent d94d387101
commit 91cc9cc9a4
3 changed files with 47 additions and 14 deletions

View File

@@ -58,6 +58,14 @@ class Editor extends Template
setCursor: ({column, row}) ->
@aceEditor.navigateTo(row, column)
selectToPosition: (position) ->
{ row, column } = @getCursor()
@aceEditor.selection.setSelectionAnchor(row, column)
@aceEditor.moveCursorToPosition(position)
delete: ->
@getAceSession().remove(@aceEditor.getSelectionRange())
getCursor: ->
@getAceSession().getSelection().getCursor()

View File

@@ -24,9 +24,18 @@ module.exports =
Delete: class
complete: null
motion: null
execute: (editor) ->
editor.deleteLine()
if @motion
@motion.select(editor)
editor.delete()
else
editor.deleteLine()
compose: (motion) ->
@motion = motion
@complete = true
isComplete: -> @complete
@@ -51,7 +60,15 @@ module.exports =
isComplete: -> true
MoveToNextWord: class
isComplete: -> true
execute: (editor) ->
editor.setCursor(@nextWordPosition(editor))
select: (editor) ->
editor.selectToPosition(@nextWordPosition(editor))
nextWordPosition: (editor) ->
regex = getWordRegex()
{ row, column } = editor.getCursor()
rightOfCursor = editor.getLineText(row).substring(column)
@@ -65,8 +82,6 @@ module.exports =
else
nextLineMatch = regex.exec(editor.getLineText(++row))
column = nextLineMatch?.index or 0
{ row, column }
editor.setCursor { row, column }
isComplete: -> true