When dd is called on the last line, it removes the \n from the previous line

Treat dd as a special, completing version of d.
This commit is contained in:
Corey Johnson
2012-02-03 17:31:39 -08:00
parent 88cf574bc6
commit 7cdcf2b358
4 changed files with 29 additions and 6 deletions

View File

@@ -53,11 +53,18 @@ describe "VimMode", ->
editor.trigger keydownEvent('d')
editor.trigger keydownEvent('d')
expect(editor.buffer.getText()).toBe "12345\nABCDE"
expect(editor.getCursorPosition()).toEqual([1,0])
describe "when the second d is prefixed by a count", ->
it "deletes the last line", ->
editor.buffer.setText("12345\nabcde\nABCDE")
editor.setCursorPosition([2,1])
editor.trigger keydownEvent('d')
editor.trigger keydownEvent('d')
expect(editor.buffer.getText()).toBe "12345\nabcde"
expect(editor.getCursorPosition()).toEqual([1,0])
xdescribe "when the second d is prefixed by a count", ->
it "deletes n lines, starting from the current", ->
editor.buffer.setText("12345\nabcde\nABCDE\nQWERT")
editor.setCursorPosition([1,1])

View File

@@ -41,6 +41,9 @@ class Buffer
getLine: (row) ->
@lines[row]
getLineLength: (row) ->
@lines[row].length
numLines: ->
@getLines().length
@@ -50,6 +53,17 @@ class Buffer
lastLine: ->
@getLine(@lastRow())
deleteRow: (row) ->
range = null
if row == @lastRow()
range = new Range([row - 1, @getLineLength(row - 1)], [row, @getLineLength(row)])
else
range = new Range([row, 0], [row + 1, 0])
console.log range
@change(range, '')
insert: (point, text) ->
@change(new Range(point, point), text)

View File

@@ -78,14 +78,15 @@ class VimMode
@pushOperator(new operators.NumericPrefix(num))
delete: () ->
if @isDeletePending()
@pushOperator(new motions.SelectLines(@editor))
if deleteOperation = @isDeletePending()
deleteOperation.complete = true
@processOpStack()
else
@pushOperator(new operators.Delete(@editor))
isDeletePending: () ->
for op in @opStack
return true if op instanceof operators.Delete
return op if op instanceof operators.Delete
false
pushOperator: (op) ->

View File

@@ -39,7 +39,8 @@ class Delete
@motion.select()
@editor.getSelection().delete()
else
@editor.deleteLine()
@editor.buffer.deleteRow(@editor.getCursorRow())
@editor.setCursorPosition([@editor.getCursorRow(), 0])
compose: (motion) ->
@motion = motion