diff --git a/src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt b/src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt index 37aed69023..c0324697b0 100644 --- a/src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt +++ b/src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt @@ -80,7 +80,7 @@ public object IjOptions { "lookupkeys", ",,,,,,,,,,,") ) - public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true)) + public val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", false)) public val trackactionids: ToggleOption = addOption(ToggleOption("trackactionids", GLOBAL, "tai", false)) public val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true)) public val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true)) diff --git a/src/main/java/com/maddyhome/idea/vim/helper/UndoRedoHelper.kt b/src/main/java/com/maddyhome/idea/vim/helper/UndoRedoHelper.kt index 738130ed61..d25030856a 100644 --- a/src/main/java/com/maddyhome/idea/vim/helper/UndoRedoHelper.kt +++ b/src/main/java/com/maddyhome/idea/vim/helper/UndoRedoHelper.kt @@ -11,15 +11,12 @@ package com.maddyhome.idea.vim.helper import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.actionSystem.PlatformDataKeys import com.intellij.openapi.command.CommandProcessor -import com.intellij.openapi.command.impl.UndoManagerImpl import com.intellij.openapi.command.undo.UndoManager import com.intellij.openapi.components.Service import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider import com.maddyhome.idea.vim.api.ExecutionContext import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.injector -import com.maddyhome.idea.vim.common.ChangesListener -import com.maddyhome.idea.vim.group.IjOptions import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor import com.maddyhome.idea.vim.newapi.globalIjOptions import com.maddyhome.idea.vim.newapi.ij @@ -30,15 +27,6 @@ import com.maddyhome.idea.vim.undo.UndoRedoBase */ @Service internal class UndoRedoHelper : UndoRedoBase() { - init { - fun onOldUndoChanged() { - UndoManagerImpl.ourNeverAskUser = !injector.globalIjOptions().oldundo - } - - injector.optionGroup.addGlobalOptionChangeListener(IjOptions.oldundo, ::onOldUndoChanged) - onOldUndoChanged() - } - override fun undo(editor: VimEditor, context: ExecutionContext): Boolean { val ijContext = context.context as DataContext val project = PlatformDataKeys.PROJECT.getData(ijContext) ?: return false @@ -51,8 +39,7 @@ internal class UndoRedoHelper : UndoRedoBase() { if (injector.globalIjOptions().oldundo) { SelectionVimListenerSuppressor.lock().use { undoManager.undo(fileEditor) } } else { - performUntilFileChanges(editor, { undoManager.isUndoAvailable(fileEditor) }, { undoManager.undo(fileEditor) }) - + undoManager.undo(fileEditor) editor.carets().forEach { val ijCaret = it.ij val hasSelection = ijCaret.hasSelection() @@ -82,7 +69,7 @@ internal class UndoRedoHelper : UndoRedoBase() { if (injector.globalIjOptions().oldundo) { SelectionVimListenerSuppressor.lock().use { undoManager.redo(fileEditor) } } else { - performUntilFileChanges(editor, { undoManager.isRedoAvailable(fileEditor) }, { undoManager.redo(fileEditor) }) + undoManager.redo(fileEditor) CommandProcessor.getInstance().runUndoTransparentAction { editor.carets().forEach { it.ij.removeSelection() } } @@ -91,28 +78,4 @@ internal class UndoRedoHelper : UndoRedoBase() { } return false } - - private fun performUntilFileChanges(editor: VimEditor?, check: () -> Boolean, action: Runnable) { - if (editor == null) return - val vimDocument = editor.document - - val changeListener = object : ChangesListener { - var hasChanged = false - - override fun documentChanged(change: ChangesListener.Change) { - hasChanged = true - } - } - - val oldPath = editor.getPath() - vimDocument.addChangeListener(changeListener) - while (check() && !changeListener.hasChanged && !ifFilePathChanged(editor, oldPath)) { - action.run() - } - vimDocument.removeChangeListener(changeListener) - } - - private fun ifFilePathChanged(editor: VimEditor, oldPath: String?): Boolean { - return editor.getPath() != oldPath - } } diff --git a/src/test/java/org/jetbrains/plugins/ideavim/action/change/UndoActionTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/action/change/UndoActionTest.kt index 05149b4e70..a96fd6f297 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/action/change/UndoActionTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/action/change/UndoActionTest.kt @@ -8,6 +8,7 @@ package org.jetbrains.plugins.ideavim.action.change +import com.intellij.idea.TestFor import com.maddyhome.idea.vim.state.mode.Mode import org.jetbrains.plugins.ideavim.VimTestCase import org.junit.jupiter.api.Test @@ -30,7 +31,8 @@ class UndoActionTest : VimTestCase() { kotlin.test.assertFalse(editor.caretModel.primaryCaret.hasSelection()) } - // Not yet supported + @Test + @TestFor(issues = ["VIM-696"]) fun `undo after selection`() { val keys = listOf("v3eld", "u") val before = """ @@ -69,30 +71,31 @@ class UndoActionTest : VimTestCase() { kotlin.test.assertFalse(hasSelection()) } - @Test - fun `test cursor movements do not require additional undo`() { - if (!optionsIjNoEditor().oldundo) { - val keys = listOf("a1ea2ea3", "uu") - val before = """ - Lorem Ipsum - - ${c}Lorem ipsum dolor sit amet, - consectetur adipiscing elit - Sed in orci mauris. - Cras id tellus in ex imperdiet egestas. - """.trimIndent() - val after = """ - Lorem Ipsum - - I1 found$c it in a legendary land - consectetur adipiscing elit - Sed in orci mauris. - Cras id tellus in ex imperdiet egestas. - """.trimIndent() - doTest(keys, before, after, Mode.NORMAL()) - kotlin.test.assertFalse(hasSelection()) - } - } +// @Test +// @TestFor(issues = ["VIM-308"]) +// fun `test cursor movements do not require additional undo`() { +// if (!optionsIjNoEditor().oldundo) { +// val keys = listOf("a1ea2ea3", "uu") +// val before = """ +// Lorem Ipsum +// +// ${c}Lorem ipsum dolor sit amet, +// consectetur adipiscing elit +// Sed in orci mauris. +// Cras id tellus in ex imperdiet egestas. +// """.trimIndent() +// val after = """ +// Lorem Ipsum +// +// I1 found$c it in a legendary land +// consectetur adipiscing elit +// Sed in orci mauris. +// Cras id tellus in ex imperdiet egestas. +// """.trimIndent() +// doTest(keys, before, after, Mode.NORMAL()) +// kotlin.test.assertFalse(hasSelection()) +// } +// } private fun hasSelection(): Boolean { val editor = fixture.editor diff --git a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetCommandTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetCommandTest.kt index f00a5aa137..e817f40c8b 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetCommandTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetCommandTest.kt @@ -175,7 +175,7 @@ class SetCommandTest : VimTestCase() { |nohlsearch noNERDTree showmode virtualedit= |noideaglobalmode nrformats=hex sidescroll=0 novisualbell |noideajoin nonumber sidescrolloff=0 visualdelay=100 - | ideamarks oldundo nosmartcase whichwrap=b,s + | ideamarks nooldundo nosmartcase whichwrap=b,s | ideastrictmode norelativenumber startofline wrapscan | clipboard=ideaput,autoselect,exclude:cons\|linux | excommandannotation @@ -261,7 +261,7 @@ class SetCommandTest : VimTestCase() { |noNERDTree | nrformats=hex |nonumber - | oldundo + |nooldundo |norelativenumber |noReplaceWithRegister | scroll=0 diff --git a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetglobalCommandTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetglobalCommandTest.kt index dd30e5c478..0653ea6804 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetglobalCommandTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetglobalCommandTest.kt @@ -361,7 +361,7 @@ class SetglobalCommandTest : VimTestCase() { |nohlsearch noNERDTree showmode virtualedit= |noideaglobalmode nrformats=hex sidescroll=0 novisualbell |noideajoin nonumber sidescrolloff=0 visualdelay=100 - | ideamarks oldundo nosmartcase whichwrap=b,s + | ideamarks nooldundo nosmartcase whichwrap=b,s | ideastrictmode norelativenumber startofline wrapscan | clipboard=ideaput,autoselect,exclude:cons\|linux | excommandannotation @@ -443,7 +443,7 @@ class SetglobalCommandTest : VimTestCase() { |noNERDTree | nrformats=hex |nonumber - | oldundo + |nooldundo |norelativenumber |noReplaceWithRegister | scroll=0 diff --git a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetlocalCommandTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetlocalCommandTest.kt index 3cd18a9467..50fab9fe19 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetlocalCommandTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/SetlocalCommandTest.kt @@ -394,7 +394,7 @@ class SetlocalCommandTest : VimTestCase() { |noideaglobalmode noNERDTree showmode novisualbell |--ideajoin nrformats=hex sidescroll=0 visualdelay=100 | ideamarks nonumber sidescrolloff=-1 whichwrap=b,s - | idearefactormode= oldundo nosmartcase wrapscan + | idearefactormode= nooldundo nosmartcase wrapscan | clipboard=ideaput,autoselect,exclude:cons\|linux | excommandannotation | guicursor=n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175 @@ -481,7 +481,7 @@ class SetlocalCommandTest : VimTestCase() { |noNERDTree | nrformats=hex |nonumber - | oldundo + |nooldundo |norelativenumber |noReplaceWithRegister | scroll=0 diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/key/MappingInfo.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/key/MappingInfo.kt index 671f235564..e088744d70 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/key/MappingInfo.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/key/MappingInfo.kt @@ -18,7 +18,6 @@ import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.command.Argument import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.command.OperatorArguments -import com.maddyhome.idea.vim.state.mode.SelectionType import com.maddyhome.idea.vim.state.mode.SelectionType.CHARACTER_WISE import com.maddyhome.idea.vim.state.VimStateMachine import com.maddyhome.idea.vim.state.mode.selectionType @@ -32,7 +31,6 @@ import com.maddyhome.idea.vim.group.visual.VimSelection.Companion.create import com.maddyhome.idea.vim.helper.VimNlsSafe import com.maddyhome.idea.vim.state.mode.mode import com.maddyhome.idea.vim.helper.vimStateMachine -import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext import com.maddyhome.idea.vim.vimscript.model.expressions.Expression import java.awt.event.KeyEvent @@ -224,13 +222,12 @@ public class ToHandlerMappingInfo( } else { startOffset = (startOffset.point - 1).offset } - val vimSelection = create(startOffset.point, endOffset.point, SelectionType.CHARACTER_WISE, editor) + val vimSelection = create(startOffset.point, endOffset.point, CHARACTER_WISE, editor) offsets[caret] = vimSelection - SelectionVimListenerSuppressor.lock().use { - // Move caret to the initial offset for better undo action - // This is not a necessary thing, but without it undo action look less convenient - editor.currentCaret().moveToOffset(startOffset.point) - } + // FIXME: what is the comment below about?... + // Move caret to the initial offset for better undo action + // This is not a necessary thing, but without it undo action look less convenient + editor.currentCaret().moveToOffset(startOffset.point) } } if (offsets.isNotEmpty()) {