Skip to content

Commit

Permalink
Fix(VIM-3552): Undo undoes paste and insert in one keypress
Browse files Browse the repository at this point in the history
  • Loading branch information
lippfi committed Jul 22, 2024
1 parent 6a10cf5 commit c2c0c2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/group/copy/PutGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.maddyhome.idea.vim.put.PutData
import com.maddyhome.idea.vim.put.VimPasteProvider
import com.maddyhome.idea.vim.put.VimPutBase
import com.maddyhome.idea.vim.register.RegisterConstants
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.SelectionType
import com.maddyhome.idea.vim.state.mode.isBlock
import com.maddyhome.idea.vim.state.mode.isChar
Expand Down Expand Up @@ -83,7 +84,7 @@ internal class PutGroup : VimPutBase() {
val editor = (vimEditor as IjVimEditor).editor
val context = vimContext.context as DataContext
val carets: MutableMap<Caret, RangeMarker> = mutableMapOf()
if (editor.isInsertMode) {
if (injector.vimState.mode is Mode.INSERT) {
val undo = injector.undo
val nanoTime = System.nanoTime()
vimEditor.forEachCaret { undo.startInsertSequence(it, it.offset, nanoTime) }
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/newapi/IjVimEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor() {
}

override fun insertText(caret: VimCaret, atPosition: Int, text: CharSequence) {
if (editor.isInsertMode) {
if (injector.vimState.mode is Mode.INSERT) {
injector.undo.startInsertSequence(caret, atPosition, System.nanoTime())
}
editor.document.insertString(atPosition, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,17 @@ class UndoActionTest : VimTestCase() {
@TestFor(issues = ["VIM-547"])
fun `test change action is included in insert sequence`() {
configureByText("Lorem ${c}ipsum dolor sit amet")
typeText("celorem")
typeText("celorem<Esc>")
assertState("Lorem lore${c}m dolor sit amet")
typeText("u")
assertState("Lorem ${c}ipsum dolor sit amet")
}

@Test
@TestFor(issues = ["VIM-3552"])
fun `test paste is not part of undo sequence`() {
configureByText("test")
typeText("yypoxxxu")
configureByText("Lorem lorem${c} dolor sit amet")
typeText("u")
configureByText("Lorem ${c}ipsum dolor sit amet")
Expand Down

0 comments on commit c2c0c2a

Please sign in to comment.