mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Implement d3d
Delete line can take a count before the second d. When the second d is typed it pushed a SelectLines operation. When a numeric prefix is composed with SelectLines, it assigns its count on select lines, which uses it to determine how many lines to select. This bypasses the normal "repeat command" semantics of numeric prefix.
This commit is contained in:
parent
9b3fc10130
commit
a647fa4220
@ -57,6 +57,18 @@ describe "VimMode", ->
|
||||
expect(editor.buffer.getText()).toBe "12345\nABCDE"
|
||||
expect(editor.getPosition()).toEqual(column: 0, row: 1)
|
||||
|
||||
describe "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.setPosition(column: 1, row: 1)
|
||||
|
||||
editor.trigger keydownEvent('d')
|
||||
editor.trigger keydownEvent('2')
|
||||
editor.trigger keydownEvent('d')
|
||||
|
||||
expect(editor.buffer.getText()).toBe "12345\nQWERT"
|
||||
expect(editor.getPosition()).toEqual(column: 0, row: 1)
|
||||
|
||||
describe "when followed by an h", ->
|
||||
it "deletes the previous letter on the current line", ->
|
||||
editor.buffer.setText("abcd\n01234")
|
||||
|
@ -74,11 +74,16 @@ class VimMode
|
||||
@pushOperator(new operators.NumericPrefix(num))
|
||||
|
||||
delete: () ->
|
||||
if @topOperator() instanceof operators.Delete
|
||||
@pushOperator(new motions.SelectLine(@editor))
|
||||
if @isDeletePending()
|
||||
@pushOperator(new motions.SelectLines(@editor))
|
||||
else
|
||||
@pushOperator(new operators.Delete(@editor))
|
||||
|
||||
isDeletePending: () ->
|
||||
for op in @opStack
|
||||
return true if op instanceof operators.Delete
|
||||
false
|
||||
|
||||
pushOperator: (op) ->
|
||||
@opStack.push(op)
|
||||
@processOpStack()
|
||||
|
@ -47,9 +47,17 @@ class MoveToNextWord extends Motion
|
||||
column = nextLineMatch?.index or 0
|
||||
{ row, column }
|
||||
|
||||
class SelectLine extends Motion
|
||||
class SelectLines extends Motion
|
||||
count: null
|
||||
|
||||
constructor: (@editor) ->
|
||||
@count = 1
|
||||
|
||||
setCount: (@count) ->
|
||||
|
||||
select: ->
|
||||
@editor.selectLine()
|
||||
@editor.setPosition(column: 0, row: @editor.getRow())
|
||||
@editor.selectToPosition(column: 0, row: @editor.getRow() + @count)
|
||||
|
||||
module.exports = { MoveLeft, MoveUp, MoveDown, MoveToNextWord, SelectLine }
|
||||
module.exports = { MoveLeft, MoveUp, MoveDown, MoveToNextWord, SelectLines }
|
||||
|
||||
|
@ -12,6 +12,9 @@ class NumericPrefix
|
||||
|
||||
compose: (@operatorToRepeat) ->
|
||||
@complete = true
|
||||
if @operatorToRepeat.setCount?
|
||||
@operatorToRepeat.setCount @count
|
||||
@count = 1
|
||||
|
||||
addDigit: (digit) ->
|
||||
@count = @count * 10 + digit
|
||||
|
Loading…
Reference in New Issue
Block a user