mirror of
https://github.com/atom/atom.git
synced 2026-02-08 21:55:05 -05:00
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:
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user