Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Commit 30e4073

Browse files
committed
Adjust replace mode backspace to work w/ new history API
As of atom/text-buffer#81, which will ship in Atom v1.0.3, the editor's history API has changed in some subtle ways in order to preserve the proper nesting of transactions. The `groupChangesSinceCheckpoint` method no longer works if called from within a transaction with a checkpoint that was created *outside* the transaction. /cc @jacekkopecky, can you double check that this alternative approach works correctly?
1 parent c384079 commit 30e4073

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/vim-state.coffee

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ class VimState
430430

431431
activateReplaceMode: ->
432432
@activateInsertMode('replace')
433-
@replaceModeCheckpoint = null
434433
@replaceModeCounter = 0
435434
@editorElement.classList.add('replace-mode')
436435
@subscriptions.add @replaceModeListener = @editor.onWillInsertText @replaceModeInsertHandler
@@ -439,20 +438,20 @@ class VimState
439438
replaceModeInsertHandler: (event) =>
440439
chars = event.text?.split('') or []
441440
selections = @editor.getSelections()
442-
@replaceModeCheckpoint = @editor.createCheckpoint()
443441
for char in chars
444442
continue if char is '\n'
445443
for selection in selections
446-
# Delete next character
447444
selection.delete() unless selection.cursor.isAtEndOfLine()
445+
return
448446

449447
replaceModeUndoHandler: (event) =>
450-
@editor.groupChangesSinceCheckpoint(@replaceModeCheckpoint) if @replaceModeCheckpoint?
451448
@replaceModeCounter++
452449

453450
replaceModeUndo: ->
454451
if @replaceModeCounter > 0
455452
@editor.undo()
453+
@editor.undo()
454+
@editor.moveLeft()
456455
@replaceModeCounter--
457456

458457
setInsertionCheckpoint: ->

spec/operators-spec.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,9 +1831,11 @@ describe "Operators", ->
18311831
keydown 'backspace', raw: true
18321832

18331833
expect(editor.getText()).toBe "12foo345\n67890"
1834+
expect(editor.getSelectedText()).toBe ""
18341835

18351836
keydown 'backspace', raw: true
18361837
expect(editor.getText()).toBe "12foo345\n67890"
1838+
expect(editor.getSelectedText()).toBe ""
18371839

18381840
it "can be repeated", ->
18391841
keydown "R", shift: true

0 commit comments

Comments
 (0)