mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-13 12:34:06 +02:00
Scroll caret into view after undo/redo
This is to ensure that 'scrolloff' is applied. Relates to VIM-3671
This commit is contained in:
parent
9d9e38843d
commit
879d191800
src/test/java/org/jetbrains/plugins/ideavim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
@ -162,6 +162,16 @@ class UndoActionTest : VimTestCase() {
|
||||
configureByText("Lorem ${c}ipsum dolor sit amet")
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestFor(issues = ["VIM-3671"])
|
||||
fun `test undo scrolls caret to reset scrolloff`() {
|
||||
configureByLines(200, "lorem ipsum dolor sit amet")
|
||||
enterCommand("set scrolloff=10")
|
||||
typeText("50G", "dd", "G", "u")
|
||||
assertPosition(49, 0)
|
||||
assertVisibleArea(39, 73)
|
||||
}
|
||||
|
||||
private fun hasSelection(): Boolean {
|
||||
val editor = fixture.editor
|
||||
return editor.caretModel.primaryCaret.hasSelection()
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
package org.jetbrains.plugins.ideavim.ex.implementation.commands
|
||||
|
||||
import com.intellij.idea.TestFor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.vimscript.model.commands.RedoCommand
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
@ -20,4 +21,15 @@ class RedoCommandTest : VimTestCase() {
|
||||
val command = injector.vimscriptParser.parseCommand("redo")
|
||||
assertTrue(command is RedoCommand)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestFor(issues = ["VIM-3671"])
|
||||
fun `test redo scrolls caret to reset scrolloff`() {
|
||||
configureByLines(200, "lorem ipsum dolor sit amet")
|
||||
enterCommand("set scrolloff=10")
|
||||
typeText("50G", "dd", "u", "G")
|
||||
enterCommand("redo")
|
||||
assertPosition(49, 0)
|
||||
assertVisibleArea(39, 73)
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
package org.jetbrains.plugins.ideavim.ex.implementation.commands
|
||||
|
||||
import com.intellij.idea.TestFor
|
||||
import com.maddyhome.idea.vim.api.injector
|
||||
import com.maddyhome.idea.vim.vimscript.model.commands.UndoCommand
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
@ -20,4 +21,15 @@ class UndoCommandTest : VimTestCase() {
|
||||
val command = injector.vimscriptParser.parseCommand("undo")
|
||||
assertTrue(command is UndoCommand)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestFor(issues = ["VIM-3671"])
|
||||
fun `test undo scrolls caret to reset scrolloff`() {
|
||||
configureByLines(200, "lorem ipsum dolor sit amet")
|
||||
enterCommand("set scrolloff=10")
|
||||
typeText("50G", "dd", "G")
|
||||
enterCommand("undo")
|
||||
assertPosition(49, 0)
|
||||
assertVisibleArea(39, 73)
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class RedoAction : VimActionHandler.SingleExecution() {
|
||||
while ((--count > 0) && result) {
|
||||
result = injector.undo.redo(editor, context)
|
||||
}
|
||||
injector.scroll.scrollCaretIntoView(editor)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class UndoAction : VimActionHandler.SingleExecution() {
|
||||
while ((--count > 0) && result) {
|
||||
result = injector.undo.undo(editor, context)
|
||||
}
|
||||
injector.scroll.scrollCaretIntoView(editor)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
data class RedoCommand(val range: Range, val argument: String) : Command.SingleExecution(range, argument) {
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.WRITABLE)
|
||||
override fun processCommand(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments): ExecutionResult {
|
||||
return if (injector.undo.redo(editor, context)) ExecutionResult.Success else ExecutionResult.Error
|
||||
return if (injector.undo.redo(editor, context)) {
|
||||
injector.scroll.scrollCaretIntoView(editor)
|
||||
ExecutionResult.Success
|
||||
} else ExecutionResult.Error
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ data class UndoCommand(val range: Range, val argument: String) : Command.SingleE
|
||||
override val argFlags: CommandHandlerFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_FORBIDDEN, Access.WRITABLE)
|
||||
|
||||
override fun processCommand(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments): ExecutionResult {
|
||||
return if (injector.undo.undo(editor, context)) ExecutionResult.Success else ExecutionResult.Error
|
||||
return if (injector.undo.undo(editor, context)) {
|
||||
injector.scroll.scrollCaretIntoView(editor)
|
||||
ExecutionResult.Success
|
||||
} else ExecutionResult.Error
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user