1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-30 22:34:08 +02:00

Remove EDT and write action from the VimTestCase

This commit is contained in:
Alex Plate 2025-02-20 21:28:30 +02:00
parent 24c0d31f14
commit 564ab7d75e
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
56 changed files with 1682 additions and 1126 deletions
src
main/java/com/maddyhome/idea/vim
test/java/org/jetbrains/plugins/ideavim
testFixtures/kotlin/org/jetbrains/plugins/ideavim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
api
vimscript/model/commands

View File

@ -15,6 +15,7 @@ import com.intellij.openapi.editor.CaretVisualAttributes
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.globalOptions import com.maddyhome.idea.vim.api.globalOptions
@ -88,7 +89,9 @@ private fun isBlockCursorOverride() = EditorSettingsExternalizable.getInstance()
private fun Editor.updatePrimaryCaretVisualAttributes() { private fun Editor.updatePrimaryCaretVisualAttributes() {
if (VimPlugin.isNotEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled") if (VimPlugin.isNotEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
if (isIdeaVimDisabledHere) return if (isIdeaVimDisabledHere) return
caretModel.primaryCaret.visualAttributes = AttributesCache.getCaretVisualAttributes(this) ApplicationManager.getApplication().invokeAndWait {
caretModel.primaryCaret.visualAttributes = AttributesCache.getCaretVisualAttributes(this)
}
// Make sure the caret is visible as soon as it's set. It might be invisible while blinking // Make sure the caret is visible as soon as it's set. It might be invisible while blinking
// NOTE: At the moment, this causes project leak in tests // NOTE: At the moment, this causes project leak in tests
@ -163,12 +166,14 @@ class CaretVisualAttributesListener : IsReplaceCharListener, ModeChangeListener,
updateCaretsVisual(editor) updateCaretsVisual(editor)
} }
@RequiresEdt
private fun updateCaretsVisual(editor: VimEditor) { private fun updateCaretsVisual(editor: VimEditor) {
val ijEditor = (editor as IjVimEditor).editor val ijEditor = (editor as IjVimEditor).editor
ijEditor.updateCaretsVisualAttributes() ijEditor.updateCaretsVisualAttributes()
ijEditor.updateCaretsVisualPosition() ijEditor.updateCaretsVisualPosition()
} }
@RequiresEdt
fun updateAllEditorsCaretsVisual() { fun updateAllEditorsCaretsVisual() {
injector.editorGroup.getEditors().forEach { editor -> injector.editorGroup.getEditors().forEach { editor ->
updateCaretsVisual(editor) updateCaretsVisual(editor)

View File

@ -13,6 +13,8 @@ import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.VisualPosition import com.intellij.openapi.editor.VisualPosition
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.maddyhome.idea.vim.api.injector
/** /**
* Move the caret to the given offset, handling inline inlays * Move the caret to the given offset, handling inline inlays
@ -35,6 +37,7 @@ import com.intellij.openapi.editor.VisualPosition
* It is recommended to call this method even if the caret hasn't been moved. It will handle the situation where the * It is recommended to call this method even if the caret hasn't been moved. It will handle the situation where the
* document has been changed to add an inlay at the caret position, and will move the caret appropriately. * document has been changed to add an inlay at the caret position, and will move the caret appropriately.
*/ */
@RequiresEdt
internal fun Caret.moveToInlayAwareOffset(offset: Int) { internal fun Caret.moveToInlayAwareOffset(offset: Int) {
// If the target is inside a fold, call the standard moveToOffset to expand and move // If the target is inside a fold, call the standard moveToOffset to expand and move
if (editor.foldingModel.isOffsetCollapsed(offset) || !editor.hasBlockOrUnderscoreCaret()) { if (editor.foldingModel.isOffsetCollapsed(offset) || !editor.hasBlockOrUnderscoreCaret()) {
@ -51,6 +54,7 @@ internal fun Caret.moveToInlayAwareLogicalPosition(pos: LogicalPosition) {
moveToInlayAwareOffset(editor.logicalPositionToOffset(pos)) moveToInlayAwareOffset(editor.logicalPositionToOffset(pos))
} }
@RequiresEdt
private fun getVisualPositionForTextAtOffset(editor: Editor, offset: Int): VisualPosition { private fun getVisualPositionForTextAtOffset(editor: Editor, offset: Int): VisualPosition {
var logicalPosition = editor.offsetToLogicalPosition(offset) var logicalPosition = editor.offsetToLogicalPosition(offset)
val e = if (editor is EditorWindow) { val e = if (editor is EditorWindow) {
@ -81,15 +85,18 @@ internal fun Editor.amountOfInlaysBeforeVisualPosition(pos: VisualPosition): Int
return this.inlayModel.getInlineElementsInRange(lineStartOffset, offset).size return this.inlayModel.getInlineElementsInRange(lineStartOffset, offset).size
} }
@RequiresEdt
internal fun Editor.updateCaretsVisualPosition() { internal fun Editor.updateCaretsVisualPosition() {
// Caret visual position depends on the current mode, especially with respect to inlays. E.g. if an inlay is // Caret visual position depends on the current mode, especially with respect to inlays. E.g. if an inlay is
// related to preceding text, the caret is placed between inlay and preceding text in insert mode (usually bar // related to preceding text, the caret is placed between inlay and preceding text in insert mode (usually bar
// caret) but after the inlay in normal mode (block caret). // caret) but after the inlay in normal mode (block caret).
// By repositioning to the same offset, we will recalculate the expected visual position and put the caret in the // By repositioning to the same offset, we will recalculate the expected visual position and put the caret in the
// right location. Don't open a fold if the caret is inside // right location. Don't open a fold if the caret is inside
this.vimForEachCaret { injector.application.runReadAction {
if (!this.foldingModel.isOffsetCollapsed(it.offset)) { this.vimForEachCaret {
it.moveToInlayAwareOffset(it.offset) if (!this.foldingModel.isOffsetCollapsed(it.offset)) {
it.moveToInlayAwareOffset(it.offset)
}
} }
} }
} }

View File

@ -160,7 +160,9 @@ internal object VimListenerManager {
injector.listenersNotifier.myEditorListeners.add(caretVisualAttributesListener) injector.listenersNotifier.myEditorListeners.add(caretVisualAttributesListener)
injector.listenersNotifier.modeChangeListeners.add(caretVisualAttributesListener) injector.listenersNotifier.modeChangeListeners.add(caretVisualAttributesListener)
injector.listenersNotifier.isReplaceCharListeners.add(caretVisualAttributesListener) injector.listenersNotifier.isReplaceCharListeners.add(caretVisualAttributesListener)
caretVisualAttributesListener.updateAllEditorsCaretsVisual() ApplicationManager.getApplication().invokeAndWait {
caretVisualAttributesListener.updateAllEditorsCaretsVisual()
}
val insertTimeRecorder = InsertTimeRecorder() val insertTimeRecorder = InsertTimeRecorder()
injector.listenersNotifier.modeChangeListeners.add(insertTimeRecorder) injector.listenersNotifier.modeChangeListeners.add(insertTimeRecorder)
@ -328,7 +330,9 @@ internal object VimListenerManager {
injector.listenersNotifier.notifyEditorCreated(vimEditor) injector.listenersNotifier.notifyEditorCreated(vimEditor)
Disposer.register(perEditorDisposable) { Disposer.register(perEditorDisposable) {
VimPlugin.getEditor().editorDeinit(editor) ApplicationManager.getApplication().invokeLater {
VimPlugin.getEditor().editorDeinit(editor)
}
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action package org.jetbrains.plugins.ideavim.action
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.KeyHandler import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
@ -185,7 +186,9 @@ class CopyActionTest : VimTestCase() {
""".trimIndent(), """.trimIndent(),
) )
kotlin.test.assertEquals(0, editor.caretModel.offset) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertEquals(0, editor.caretModel.offset)
}
} }
// VIM-632 |CTRL-V| |v_y| |p| // VIM-632 |CTRL-V| |v_y| |p|

View File

@ -264,7 +264,7 @@ class MacroActionTest : VimTestCase() {
typeText("@q") typeText("@q")
} }
} }
assertEquals(ExceptionHandler.exceptionMessage, exception.cause!!.cause!!.message) assertEquals(ExceptionHandler.exceptionMessage, exception.cause!!.cause!!.cause!!.message)
assertTrue(KeyHandler.getInstance().keyStack.isEmpty()) assertTrue(KeyHandler.getInstance().keyStack.isEmpty())
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action package org.jetbrains.plugins.ideavim.action
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.motion.search.SearchWholeWordForwardAction import com.maddyhome.idea.vim.action.motion.search.SearchWholeWordForwardAction
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
@ -2184,15 +2185,17 @@ rtyfg${c}hzxc"""
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh") injector.registerGroup.storeText(vimEditor, context, '*', "fgh")
VimPlugin.getRegister() ApplicationManager.getApplication().runWriteAction {
.storeText( VimPlugin.getRegister()
IjVimEditor(editor), .storeText(
context, IjVimEditor(editor),
editor.vim.primaryCaret(), context,
TextRange(16, 19), editor.vim.primaryCaret(),
SelectionType.CHARACTER_WISE, TextRange(16, 19),
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("\"*P")) typeText(injector.parser.parseKeys("\"*P"))
val after = "fg${c}hqfg${c}hwe asd zxc rty fg${c}hfgh vbn" val after = "fg${c}hqfg${c}hwe asd zxc rty fg${c}hfgh vbn"
assertState(after) assertState(after)

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action package org.jetbrains.plugins.ideavim.action
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.MappingMode import com.maddyhome.idea.vim.command.MappingMode
@ -27,7 +28,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Lorem Ipsum" val after = "Lorem Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -36,7 +39,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Lorem Ipsum" val after = "Lorem Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -45,7 +50,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "A Disc${c}overy" val before = "A Disc${c}overy"
val after = "A Dis${c}covery" val after = "A Dis${c}covery"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -54,7 +61,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "${c}Lorem Ipsum" val before = "${c}Lorem Ipsum"
val after = "Lorem Ipsum" val after = "Lorem Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -63,7 +72,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Lorem Ipsum" val after = "Lorem Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -72,7 +83,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Lorem Ipsum" val after = "Lorem Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -81,7 +94,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Lorem Ipsum" val after = "Lorem Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -90,7 +105,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Ipsum" val after = "Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -99,7 +116,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Ipsum" val after = "Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -108,7 +127,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Ipsum" val after = "Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@TestWithoutNeovim(SkipNeovimReason.CTRL_CODES) @TestWithoutNeovim(SkipNeovimReason.CTRL_CODES)
@ -118,7 +139,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Ipsum" val after = "Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@TestWithoutNeovim(SkipNeovimReason.MAPPING) @TestWithoutNeovim(SkipNeovimReason.MAPPING)
@ -137,7 +160,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Ipsum" val after = "Ipsum"
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -146,7 +171,9 @@ class ResetModeActionTest : VimTestCase() {
val before = "Lorem Ipsum" val before = "Lorem Ipsum"
val after = "Lnotherorem Ipsum" val after = "Lnotherorem Ipsum"
doTest(keys, before, after, Mode.INSERT) doTest(keys, before, after, Mode.INSERT)
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
@Test @Test
@ -155,6 +182,8 @@ class ResetModeActionTest : VimTestCase() {
val before = "A ${c}Discovery" val before = "A ${c}Discovery"
val after = "A " val after = "A "
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(fixture.editor.selectionModel.hasSelection())
}
} }
} }

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.action.change package org.jetbrains.plugins.ideavim.action.change
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.globalIjOptions import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.state.mode.Mode
@ -31,7 +32,9 @@ class UndoActionTest : VimTestCase() {
val after = before val after = before
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
val editor = fixture.editor val editor = fixture.editor
kotlin.test.assertFalse(editor.caretModel.primaryCaret.hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(editor.caretModel.primaryCaret.hasSelection())
}
} }
@Test @Test
@ -56,7 +59,9 @@ class UndoActionTest : VimTestCase() {
Cras id tellus in ex imperdiet egestas. Cras id tellus in ex imperdiet egestas.
""".trimIndent() """.trimIndent()
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(hasSelection())
}
} }
} }
@ -80,7 +85,9 @@ class UndoActionTest : VimTestCase() {
Cras id tellus in ex imperdiet egestas. Cras id tellus in ex imperdiet egestas.
""".trimIndent() """.trimIndent()
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(hasSelection())
}
} }
@Test @Test
@ -105,7 +112,9 @@ class UndoActionTest : VimTestCase() {
Cras id tellus in ex imperdiet egestas. Cras id tellus in ex imperdiet egestas.
""".trimIndent() """.trimIndent()
doTest(keys, before, after, Mode.NORMAL()) doTest(keys, before, after, Mode.NORMAL())
kotlin.test.assertFalse(hasSelection()) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertFalse(hasSelection())
}
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.change.delete package org.jetbrains.plugins.ideavim.action.change.delete
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -118,7 +119,9 @@ class DeleteCharacterLeftActionTest : VimTestCase() {
// Scroll 70 characters to the left. First character on line should now be 71. sidescrolloff puts us at 76 // Scroll 70 characters to the left. First character on line should now be 71. sidescrolloff puts us at 76
typeText("70zl") typeText("70zl")
assertVisualPosition(0, 75) assertVisualPosition(0, 75)
assertVisibleLineBounds(0, 70, 149) ApplicationManager.getApplication().invokeAndWait {
assertVisibleLineBounds(0, 70, 149)
}
typeText("20X") typeText("20X")

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.action.change.insert package org.jetbrains.plugins.ideavim.action.change.insert
import com.intellij.codeInsight.daemon.impl.HintRenderer import com.intellij.codeInsight.daemon.impl.HintRenderer
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
@ -147,9 +148,11 @@ class VisualBlockInsertActionTest : VimTestCase() {
hard by the torrent of a mountain pass. hard by the torrent of a mountain pass.
""".trimIndent(), """.trimIndent(),
) { ) {
it.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
it.inlayModel.addInlineElement(before.indexOf("l rocks"), HintRenderer("Hello")) it.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello"))
it.inlayModel.addInlineElement(before.indexOf("ere it"), HintRenderer("Hello")) it.inlayModel.addInlineElement(before.indexOf("l rocks"), HintRenderer("Hello"))
it.inlayModel.addInlineElement(before.indexOf("ere it"), HintRenderer("Hello"))
}
} }
} }

View File

@ -11,6 +11,7 @@ package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.notification.ActionCenter import com.intellij.notification.ActionCenter
import com.intellij.notification.EventLog import com.intellij.notification.EventLog
import com.intellij.notification.Notification import com.intellij.notification.Notification
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.NotificationService import com.maddyhome.idea.vim.group.NotificationService
@ -34,14 +35,16 @@ class IdeaPutNotificationsTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("p")) typeText(injector.parser.parseKeys("p"))
val notification = notifications().last() val notification = notifications().last()
@ -62,14 +65,16 @@ class IdeaPutNotificationsTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("p")) typeText(injector.parser.parseKeys("p"))
val notifications = notifications() val notifications = notifications()
@ -88,14 +93,16 @@ class IdeaPutNotificationsTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("p")) typeText(injector.parser.parseKeys("p"))
val notifications = EventLog.getLogModel(fixture.project).notifications val notifications = EventLog.getLogModel(fixture.project).notifications

View File

@ -11,6 +11,7 @@ package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.codeInsight.editorActions.CopyPastePostProcessor import com.intellij.codeInsight.editorActions.CopyPastePostProcessor
import com.intellij.codeInsight.editorActions.CopyPastePreProcessor import com.intellij.codeInsight.editorActions.CopyPastePreProcessor
import com.intellij.codeInsight.editorActions.TextBlockTransferableData import com.intellij.codeInsight.editorActions.TextBlockTransferableData
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.CaretStateTransferableData import com.intellij.openapi.editor.CaretStateTransferableData
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
@ -88,14 +89,16 @@ class PutTestAfterCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("p")) typeText(injector.parser.parseKeys("p"))
val after = """ val after = """
A Discovery A Discovery
@ -130,18 +133,22 @@ class PutTestAfterCursorActionTest : VimTestCase() {
val editor = configureByText(before) val editor = configureByText(before)
// Add Guard to simulate Notebook behaviour. See (VIM-2577) // Add Guard to simulate Notebook behaviour. See (VIM-2577)
val guardRange = before rangeOf "\nGUARD\n" val guardRange = before rangeOf "\nGUARD\n"
editor.document.createGuardedBlock(guardRange.startOffset, guardRange.endOffset) ApplicationManager.getApplication().runReadAction {
editor.document.createGuardedBlock(guardRange.startOffset, guardRange.endOffset)
}
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "I found it in a legendary land\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "I found it in a legendary land\n",
false, SelectionType.LINE_WISE,
) false,
)
}
typeText(injector.parser.parseKeys("p")) typeText(injector.parser.parseKeys("p"))
val after = """ val after = """
A Discovery A Discovery
@ -168,14 +175,16 @@ class PutTestAfterCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("vep")) typeText(injector.parser.parseKeys("vep"))
val after = """ val after = """
A Discovery A Discovery

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.copy package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.SelectionType import com.maddyhome.idea.vim.state.mode.SelectionType
@ -33,14 +34,16 @@ class PutTextBeforeCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "P")) typeText(injector.parser.parseKeys("V" + "P"))
typeText(injector.parser.parseKeys("V" + "P")) typeText(injector.parser.parseKeys("V" + "P"))
val after = """ val after = """

View File

@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.codeInsight.editorActions.TextBlockTransferable import com.intellij.codeInsight.editorActions.TextBlockTransferable
import com.intellij.ide.CopyPasteManagerEx import com.intellij.ide.CopyPasteManagerEx
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.ide.CopyPasteManager import com.intellij.openapi.ide.CopyPasteManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
@ -58,14 +59,16 @@ class PutViaIdeaTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText("ppp") typeText("ppp")
val after = "Ilegendarylegendarylegendar${c}y found it in a legendary land" val after = "Ilegendarylegendarylegendar${c}y found it in a legendary land"
@ -85,14 +88,16 @@ class PutViaIdeaTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary$randomUUID", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary$randomUUID",
false, SelectionType.CHARACTER_WISE,
) false,
)
}
val sizeBefore = CopyPasteManager.getInstance().allContents.size val sizeBefore = CopyPasteManager.getInstance().allContents.size
typeText("ve", "p") typeText("ve", "p")
@ -114,14 +119,16 @@ class PutViaIdeaTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "\nLorem ipsum dolor sit amet,\n", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "\nLorem ipsum dolor sit amet,\n",
false, SelectionType.CHARACTER_WISE,
) false,
)
}
typeText("p") typeText("p")
val after = """ val after = """

View File

@ -10,6 +10,7 @@
package org.jetbrains.plugins.ideavim.action.copy package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.SelectionType import com.maddyhome.idea.vim.state.mode.SelectionType
@ -78,14 +79,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "p")) typeText(injector.parser.parseKeys("ve" + "p"))
val after = "legendar${c}y it in a legendary land" val after = "legendar${c}y it in a legendary land"
assertState(after) assertState(after)
@ -101,14 +104,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v2e" + "2p")) typeText(injector.parser.parseKeys("v2e" + "2p"))
val after = "legendarylegendar${c}y in a legendary land" val after = "legendarylegendar${c}y in a legendary land"
assertState(after) assertState(after)
@ -124,14 +129,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v$" + "2p")) typeText(injector.parser.parseKeys("v$" + "2p"))
val after = "legendarylegendar${c}y" val after = "legendarylegendar${c}y"
assertState(after) assertState(after)
@ -173,14 +180,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("vb" + "p")) typeText(injector.parser.parseKeys("vb" + "p"))
val after = "I legendar${c}y it in a legendary land" val after = "I legendar${c}y it in a legendary land"
assertState(after) assertState(after)
@ -205,14 +214,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "p")) typeText(injector.parser.parseKeys("ve" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -244,14 +255,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "p")) typeText(injector.parser.parseKeys("ve" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -283,14 +296,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "p")) typeText(injector.parser.parseKeys("ve" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -322,14 +337,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v$" + "p")) typeText(injector.parser.parseKeys("v$" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -562,14 +579,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "p")) typeText(injector.parser.parseKeys("ve" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -609,14 +628,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "p")) typeText(injector.parser.parseKeys("ve" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -658,14 +679,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("ve" + "2p")) typeText(injector.parser.parseKeys("ve" + "2p"))
val after = """ val after = """
A Discovery A Discovery
@ -704,7 +727,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE)
}
// registerService.storeText(editor.vim context,, editor.rangeOf("|found|", 2), SelectionType.BLOCK_WISE, false) // registerService.storeText(editor.vim context,, editor.rangeOf("|found|", 2), SelectionType.BLOCK_WISE, false)
typeText(injector.parser.parseKeys("ve" + "\"+p")) typeText(injector.parser.parseKeys("ve" + "\"+p"))
val after = """ val after = """
@ -744,7 +769,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE)
}
// registerService.storeText(editor.vim context,, editor.rangeOf("|found|", 2), SelectionType.BLOCK_WISE, false) // registerService.storeText(editor.vim context,, editor.rangeOf("|found|", 2), SelectionType.BLOCK_WISE, false)
typeText(injector.parser.parseKeys("ve" + "\"+p")) typeText(injector.parser.parseKeys("ve" + "\"+p"))
val after = """ val after = """
@ -784,14 +811,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "p")) typeText(injector.parser.parseKeys("V" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -821,14 +850,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "2p")) typeText(injector.parser.parseKeys("V" + "2p"))
val after = """ val after = """
A Discovery A Discovery
@ -869,14 +900,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "p")) typeText(injector.parser.parseKeys("V" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -914,7 +947,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "Discovery", SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '*', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"*p")) typeText(injector.parser.parseKeys("V" + "\"*p"))
val after = """ val after = """
A Discovery A Discovery
@ -952,7 +987,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -990,7 +1027,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1028,7 +1067,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1061,14 +1102,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "p")) typeText(injector.parser.parseKeys("V" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1098,14 +1141,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "2p")) typeText(injector.parser.parseKeys("V" + "2p"))
val after = """ val after = """
A Discovery A Discovery
@ -1146,14 +1191,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "p")) typeText(injector.parser.parseKeys("V" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1191,7 +1238,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "A Discovery\n", SelectionType.LINE_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '*', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"*p")) typeText(injector.parser.parseKeys("V" + "\"*p"))
val after = """ val after = """
A Discovery A Discovery
@ -1229,7 +1278,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1267,7 +1318,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1305,7 +1358,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1343,14 +1398,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "p")) typeText(injector.parser.parseKeys("V" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1409,14 +1466,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "p")) typeText(injector.parser.parseKeys("V" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1481,14 +1540,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "2p")) typeText(injector.parser.parseKeys("V" + "2p"))
val after = """ val after = """
A Discovery A Discovery
@ -1549,7 +1610,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1612,7 +1675,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before) configureByText(before)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE) ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p")) typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """ val after = """
A Discovery A Discovery
@ -1672,14 +1737,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "p")) typeText(injector.parser.parseKeys("<C-V>2e2j" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1709,14 +1776,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>3e2k" + "p")) typeText(injector.parser.parseKeys("<C-V>3e2k" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1746,14 +1815,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "2p")) typeText(injector.parser.parseKeys("<C-V>2e2j" + "2p"))
val after = """ val after = """
A Discovery A Discovery
@ -1783,14 +1854,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "Discovery", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, before rangeOf "Discovery",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>3j$" + "p")) typeText(injector.parser.parseKeys("<C-V>3j$" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1833,14 +1906,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "p")) typeText(injector.parser.parseKeys("<C-V>2e2j" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -1872,14 +1947,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "P")) typeText(injector.parser.parseKeys("<C-V>2e2j" + "P"))
val after = """ val after = """
A Discovery A Discovery
@ -1922,14 +1999,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "2p")) typeText(injector.parser.parseKeys("<C-V>2e2j" + "2p"))
val after = """ val after = """
A Discovery A Discovery
@ -1973,14 +2052,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e3j" + "p")) typeText(injector.parser.parseKeys("<C-V>2e3j" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -2023,14 +2104,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
before rangeOf "A Discovery\n", vimEditor.primaryCaret(),
SelectionType.LINE_WISE, before rangeOf "A Discovery\n",
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2j$" + "p")) typeText(injector.parser.parseKeys("<C-V>2j$" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -2069,14 +2152,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "p")) typeText(injector.parser.parseKeys("<C-V>2e2j" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -2116,14 +2201,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2e3j" + "p")) typeText(injector.parser.parseKeys("<C-V>2e3j" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -2163,14 +2250,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2ej" + "p")) typeText(injector.parser.parseKeys("<C-V>2ej" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -2209,14 +2298,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>elj" + "p")) typeText(injector.parser.parseKeys("<C-V>elj" + "p"))
val after = """ val after = """
A Discovery A Discovery
@ -2257,14 +2348,16 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runWriteAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
editor.rangeOf("|found|", 2), vimEditor.primaryCaret(),
SelectionType.BLOCK_WISE, editor.rangeOf("|found|", 2),
false SelectionType.BLOCK_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-V>2j$" + "p")) typeText(injector.parser.parseKeys("<C-V>2j$" + "p"))
val after = """ val after = """
A Discovery A Discovery

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.copy package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
@ -34,14 +35,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, TextRange(16, 25),
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v2e" + "2gp")) typeText(injector.parser.parseKeys("v2e" + "2gp"))
val after = "legendarylegendary$c in a legendary land" val after = "legendarylegendary$c in a legendary land"
assertState(after) assertState(after)
@ -55,14 +58,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.LINE_WISE, TextRange(16, 25),
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v2e" + "gp")) typeText(injector.parser.parseKeys("v2e" + "gp"))
val after = """ val after = """
@ -80,14 +85,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, TextRange(16, 25),
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "gp")) typeText(injector.parser.parseKeys("V" + "gp"))
val after = "legendary\n$c" val after = "legendary\n$c"
assertState(after) assertState(after)
@ -116,14 +123,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(2, 11), vimEditor.primaryCaret(),
SelectionType.LINE_WISE, TextRange(2, 11),
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "gp")) typeText(injector.parser.parseKeys("V" + "gp"))
assertState(newFile) assertState(newFile)
} }
@ -171,14 +180,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.LINE_WISE, TextRange(16, 25),
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v2e" + "gP")) typeText(injector.parser.parseKeys("v2e" + "gP"))
val after = """ val after = """
@ -196,14 +207,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, TextRange(16, 25),
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v2e" + "2gP")) typeText(injector.parser.parseKeys("v2e" + "2gP"))
val after = "legendarylegendary$c in a legendary land" val after = "legendarylegendary$c in a legendary land"
assertState(after) assertState(after)
@ -217,14 +230,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, TextRange(16, 25),
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("v$" + "2gP")) typeText(injector.parser.parseKeys("v$" + "2gP"))
val after = "legendarylegendar${c}y" val after = "legendarylegendar${c}y"
assertState(after) assertState(after)
@ -238,14 +253,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 25), vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, TextRange(16, 25),
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "gP")) typeText(injector.parser.parseKeys("V" + "gP"))
val after = "legendary\n$c" val after = "legendary\n$c"
assertState(after) assertState(after)
@ -385,14 +402,16 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
registerService.storeText( ApplicationManager.getApplication().runReadAction {
vimEditor, registerService.storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
TextRange(16, 19), vimEditor.primaryCaret(),
SelectionType.LINE_WISE, TextRange(16, 19),
false SelectionType.LINE_WISE,
) false
)
}
typeText(injector.parser.parseKeys("<C-v>" + "h" + "gp")) typeText(injector.parser.parseKeys("<C-v>" + "h" + "gp"))
val after = """ val after = """
q q

View File

@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.action.motion.mark
import com.intellij.ide.bookmark.BookmarksManager import com.intellij.ide.bookmark.BookmarksManager
import com.intellij.ide.bookmark.LineBookmark import com.intellij.ide.bookmark.LineBookmark
import com.intellij.openapi.application.ApplicationManager
import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.PlatformTestUtil
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.createLineBookmark import com.maddyhome.idea.vim.group.createLineBookmark
@ -101,7 +102,9 @@ class MotionMarkActionTest : VimTestCase() {
""".trimIndent() """.trimIndent()
configureByText(text) configureByText(text)
fixture.project.createLineBookmark(fixture.editor, 2, 'A') fixture.project.createLineBookmark(fixture.editor, 2, 'A')
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
val vimMarks = injector.markService.getAllGlobalMarks() val vimMarks = injector.markService.getAllGlobalMarks()
kotlin.test.assertEquals(1, vimMarks.size) kotlin.test.assertEquals(1, vimMarks.size)
kotlin.test.assertEquals('A', vimMarks.first().key) kotlin.test.assertEquals('A', vimMarks.first().key)
@ -123,7 +126,9 @@ class MotionMarkActionTest : VimTestCase() {
BookmarksManager.getInstance(fixture.project)?.remove(bookmark!!) BookmarksManager.getInstance(fixture.project)?.remove(bookmark!!)
fixture.project.createLineBookmark(fixture.editor, 4, 'A') fixture.project.createLineBookmark(fixture.editor, 4, 'A')
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
val vimMarks = injector.markService.getAllGlobalMarks() val vimMarks = injector.markService.getAllGlobalMarks()
kotlin.test.assertEquals(1, vimMarks.size) kotlin.test.assertEquals(1, vimMarks.size)
val mark = vimMarks.first() val mark = vimMarks.first()

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.motion.screen package org.jetbrains.plugins.ideavim.action.motion.screen
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.getOffset import com.maddyhome.idea.vim.api.getOffset
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
@ -178,7 +179,9 @@ class MotionFirstScreenLineActionTest : VimTestCase() {
fun `test move caret to first line of screen with inlays`() { fun `test move caret to first line of screen with inlays`() {
// We're not scrolling, so inlays don't affect anything. Just place the caret on the first visible line // We're not scrolling, so inlays don't affect anything. Just place the caret on the first visible line
configureByLines(50, " I found it in a legendary land") configureByLines(50, " I found it in a legendary land")
addBlockInlay(fixture.editor.vim.getOffset(5, 5), true, 10) ApplicationManager.getApplication().invokeAndWait {
addBlockInlay(fixture.editor.vim.getOffset(5, 5), true, 10)
}
setPositionAndScroll(0, 20, 10) setPositionAndScroll(0, 20, 10)
typeText("H") typeText("H")
assertPosition(0, 4) assertPosition(0, 4)

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.motion.select package org.jetbrains.plugins.ideavim.action.motion.select
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Caret import com.intellij.openapi.editor.Caret
import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
@ -341,9 +342,11 @@ class SelectEscapeActionTest : VimTestCase() {
""".trimIndent(), """.trimIndent(),
Mode.NORMAL(), Mode.NORMAL(),
) )
kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection)) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount) kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection))
assertCaretsVisualAttributes() kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount)
assertCaretsVisualAttributes()
}
} }
@TestWithoutNeovim(SkipNeovimReason.SELECT_MODE) @TestWithoutNeovim(SkipNeovimReason.SELECT_MODE)
@ -369,9 +372,11 @@ class SelectEscapeActionTest : VimTestCase() {
""".trimIndent(), """.trimIndent(),
Mode.NORMAL(), Mode.NORMAL(),
) )
kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection)) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount) kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection))
assertCaretsVisualAttributes() kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount)
assertCaretsVisualAttributes()
}
} }
@TestWithoutNeovim(SkipNeovimReason.SELECT_MODE) @TestWithoutNeovim(SkipNeovimReason.SELECT_MODE)
@ -397,9 +402,11 @@ class SelectEscapeActionTest : VimTestCase() {
""".trimIndent(), """.trimIndent(),
Mode.NORMAL(), Mode.NORMAL(),
) )
kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection)) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount) kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection))
assertCaretsVisualAttributes() kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount)
assertCaretsVisualAttributes()
}
} }
@TestWithoutNeovim(SkipNeovimReason.SELECT_MODE) @TestWithoutNeovim(SkipNeovimReason.SELECT_MODE)
@ -425,8 +432,10 @@ class SelectEscapeActionTest : VimTestCase() {
""".trimIndent(), """.trimIndent(),
Mode.NORMAL(), Mode.NORMAL(),
) )
kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection)) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount) kotlin.test.assertFalse(fixture.editor.caretModel.allCarets.any(Caret::hasSelection))
assertCaretsVisualAttributes() kotlin.test.assertEquals(1, fixture.editor.caretModel.caretCount)
assertCaretsVisualAttributes()
}
} }
} }

View File

@ -11,6 +11,7 @@
package org.jetbrains.plugins.ideavim.action.motion.updown package org.jetbrains.plugins.ideavim.action.motion.updown
import com.intellij.codeInsight.daemon.impl.HintRenderer import com.intellij.codeInsight.daemon.impl.HintRenderer
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.SelectionType import com.maddyhome.idea.vim.state.mode.SelectionType
@ -219,7 +220,9 @@ class MotionDownActionTest : VimTestCase() {
all rocks and la${c}vender and tufted grass, all rocks and la${c}vender and tufted grass,
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(2, HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(2, HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -236,7 +239,9 @@ class MotionDownActionTest : VimTestCase() {
all rocks and la${c}vender and tufted grass, all rocks and la${c}vender and tufted grass,
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -253,8 +258,10 @@ class MotionDownActionTest : VimTestCase() {
all rocks and la${c}vender and tufted grass, all rocks and la${c}vender and tufted grass,
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello")) fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello"))
fixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -271,7 +278,9 @@ class MotionDownActionTest : VimTestCase() {
all rocks and lavende${c}r all rocks and lavende${c}r
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -288,7 +297,9 @@ class MotionDownActionTest : VimTestCase() {
all rocks and lavender all rocks and lavender
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -321,7 +332,9 @@ class MotionDownActionTest : VimTestCase() {
all rocks and lavende${c}r all rocks and lavende${c}r
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -341,7 +354,9 @@ class MotionDownActionTest : VimTestCase() {
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
val inlayOffset = fixture.editor.document.getLineEndOffset(1) val inlayOffset = fixture.editor.document.getLineEndOffset(1)
fixture.editor.inlayModel.addInlineElement(inlayOffset, HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(inlayOffset, HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }
@ -358,7 +373,9 @@ class MotionDownActionTest : VimTestCase() {
all rocks and lavender all rocks and lavender
""".trimIndent() """.trimIndent()
configureByText(before) configureByText(before)
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello")) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello"))
}
typeText(keys) typeText(keys)
assertState(after) assertState(after)
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.motion.updown package org.jetbrains.plugins.ideavim.action.motion.updown
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
@ -62,7 +63,9 @@ class MotionUpActionTest : VimTestCase() {
) { ) {
// Simulate the caret being moved without IdeaVim knowing and therefore without vimLastColumn being updated // Simulate the caret being moved without IdeaVim knowing and therefore without vimLastColumn being updated
// This offset is effectively "lave${c}nder" // This offset is effectively "lave${c}nder"
it.caretModel.primaryCaret.moveToOffset(49) ApplicationManager.getApplication().invokeAndWait {
it.caretModel.primaryCaret.moveToOffset(49)
}
} }
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.scroll package org.jetbrains.plugins.ideavim.action.scroll
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Inlay import com.intellij.openapi.editor.Inlay
import com.maddyhome.idea.vim.helper.EditorHelper import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
@ -68,13 +69,15 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
configureByColumns(200) configureByColumns(200)
val inlay = addInlay(99, false, 5) val inlay = addInlay(99, false, 5)
typeText("100|", "zs") typeText("100|", "zs")
val visibleArea = fixture.editor.scrollingModel.visibleArea ApplicationManager.getApplication().invokeAndWait {
val textWidth = visibleArea.width - inlay.widthInPixels val visibleArea = fixture.editor.scrollingModel.visibleArea
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt() val textWidth = visibleArea.width - inlay.widthInPixels
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
// The first visible text column will be 99, with the inlay positioned to the left of it // The first visible text column will be 99, with the inlay positioned to the left of it
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1) assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
assertEquals(visibleArea.x, inlay.bounds!!.x) assertEquals(visibleArea.x, inlay.bounds!!.x)
}
} }
@Test @Test
@ -92,8 +95,10 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
configureByColumns(200) configureByColumns(200)
val inlay = addInlay(100, false, 5) val inlay = addInlay(100, false, 5)
typeText("100|", "zs") typeText("100|", "zs")
val availableColumns = getAvailableColumns(inlay) ApplicationManager.getApplication().invokeAndWait {
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1) val availableColumns = getAvailableColumns(inlay)
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
}
} }
@Test @Test
@ -102,8 +107,10 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
configureByColumns(200) configureByColumns(200)
val inlay = addInlay(100, true, 5) val inlay = addInlay(100, true, 5)
typeText("100|", "zs") typeText("100|", "zs")
val availableColumns = getAvailableColumns(inlay) ApplicationManager.getApplication().invokeAndWait {
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1) val availableColumns = getAvailableColumns(inlay)
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
}
} }
private fun getAvailableColumns(inlay: Inlay<*>): Int { private fun getAvailableColumns(inlay: Inlay<*>): Int {

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.scroll package org.jetbrains.plugins.ideavim.action.scroll
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Inlay import com.intellij.openapi.editor.Inlay
import com.maddyhome.idea.vim.helper.EditorHelper import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
@ -103,17 +104,19 @@ class ScrollLastScreenColumnActionTest : VimTestCase() {
configureByColumns(200) configureByColumns(200)
val inlay = addInlay(100, true, 5) val inlay = addInlay(100, true, 5)
typeText("100|", "ze") typeText("100|", "ze")
val visibleArea = fixture.editor.scrollingModel.visibleArea ApplicationManager.getApplication().invokeAndWait {
val textWidth = visibleArea.width - inlay.widthInPixels val visibleArea = fixture.editor.scrollingModel.visibleArea
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt() val textWidth = visibleArea.width - inlay.widthInPixels
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
// The last visible text column will be 99, but it will be positioned before the inlay // The last visible text column will be 99, but it will be positioned before the inlay
assertVisibleLineBounds(0, 99 - availableColumns + 1, 99) assertVisibleLineBounds(0, 99 - availableColumns + 1, 99)
// We have to assert the location of the inlay // We have to assert the location of the inlay
val inlayX = fixture.editor.visualPositionToPoint2D(inlay.visualPosition).x.roundToInt() val inlayX = fixture.editor.visualPositionToPoint2D(inlay.visualPosition).x.roundToInt()
assertEquals(visibleArea.x + textWidth, inlayX) assertEquals(visibleArea.x + textWidth, inlayX)
assertEquals(visibleArea.x + visibleArea.width, inlayX + inlay.widthInPixels) assertEquals(visibleArea.x + visibleArea.width, inlayX + inlay.widthInPixels)
}
} }
@Test @Test
@ -127,7 +130,11 @@ class ScrollLastScreenColumnActionTest : VimTestCase() {
} }
private fun getAvailableColumns(inlay: Inlay<*>): Int { private fun getAvailableColumns(inlay: Inlay<*>): Int {
val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels var res: Int? = null
return (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt() ApplicationManager.getApplication().invokeAndWait {
val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels
res = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
}
return res!!
} }
} }

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.ex package org.jetbrains.plugins.ideavim.ex
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
@ -96,7 +97,11 @@ class ExEntryTest : VimTestCase() {
assertIsDeactivated() assertIsDeactivated()
deactivateExEntry() deactivateExEntry()
VimPlugin.getOptionGroup().resetAllOptions(fixture.editor.vim) ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
VimPlugin.getOptionGroup().resetAllOptions(fixture.editor.vim)
}
}
assertFalse(options().incsearch) assertFalse(options().incsearch)
typeExInput(":set incsearch<C-J>") typeExInput(":set incsearch<C-J>")
@ -104,7 +109,9 @@ class ExEntryTest : VimTestCase() {
assertIsDeactivated() assertIsDeactivated()
deactivateExEntry() deactivateExEntry()
VimPlugin.getOptionGroup().resetAllOptions(fixture.editor.vim) ApplicationManager.getApplication().runReadAction {
VimPlugin.getOptionGroup().resetAllOptions(fixture.editor.vim)
}
assertFalse(options().incsearch) assertFalse(options().incsearch)
typeExInput(":set incsearch<C-M>") typeExInput(":set incsearch<C-M>")

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.ex package org.jetbrains.plugins.ideavim.ex
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
@ -131,8 +132,10 @@ class MultipleCaretsTest : VimTestCase() {
val editor = configureByText(before) val editor = configureByText(before)
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runWriteAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
}
typeText(commandToKeys("pu")) typeText(commandToKeys("pu"))
val after = """ val after = """
qwe qwe
@ -167,8 +170,10 @@ class MultipleCaretsTest : VimTestCase() {
val editor = configureByText(before) val editor = configureByText(before)
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runWriteAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
}
typeText(commandToKeys("pu")) typeText(commandToKeys("pu"))
val after = """ val after = """
qwe qwe
@ -204,8 +209,10 @@ class MultipleCaretsTest : VimTestCase() {
val editor = configureByText(before) val editor = configureByText(before)
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runWriteAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
}
typeText(commandToKeys("4pu")) typeText(commandToKeys("4pu"))
val after = """ val after = """
qwe qwe
@ -241,8 +248,10 @@ class MultipleCaretsTest : VimTestCase() {
val editor = configureByText(before) val editor = configureByText(before)
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runWriteAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
}
typeText(commandToKeys("4pu")) typeText(commandToKeys("4pu"))
val after = """ val after = """
qwe qwe
@ -264,8 +273,10 @@ class MultipleCaretsTest : VimTestCase() {
val editor = configureByText(before) val editor = configureByText(before)
val vimEditor = editor.vim val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runWriteAction {
.storeText(vimEditor, context, editor.vim.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, editor.vim.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
}
typeText("vj") typeText("vj")
typeText(commandToKeys("pu")) typeText(commandToKeys("pu"))

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -20,8 +21,10 @@ class BufferCloseCommandTest : VimTestCase() {
val psiFile1 = fixture.configureByText("A_Discovery1", "Lorem ipsum dolor sit amet,") val psiFile1 = fixture.configureByText("A_Discovery1", "Lorem ipsum dolor sit amet,")
val psiFile2 = fixture.configureByText("A_Discovery2", "consectetur adipiscing elit") val psiFile2 = fixture.configureByText("A_Discovery2", "consectetur adipiscing elit")
fileManager.openFile(psiFile1.virtualFile, false) ApplicationManager.getApplication().invokeAndWait {
fileManager.openFile(psiFile2.virtualFile, true) fileManager.openFile(psiFile1.virtualFile, false)
fileManager.openFile(psiFile2.virtualFile, true)
}
assertPluginError(false) assertPluginError(false)
typeText(commandToKeys("bd")) typeText(commandToKeys("bd"))

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -22,7 +23,9 @@ class ExitCommandTest : VimTestCase() {
} }
@Suppress("IdeaVimAssertState") @Suppress("IdeaVimAssertState")
val psiFile = fixture.configureByText("A_Discovery", "Lorem ipsum dolor sit amet,") val psiFile = fixture.configureByText("A_Discovery", "Lorem ipsum dolor sit amet,")
fileManager.openFile(psiFile.virtualFile, false) ApplicationManager.getApplication().invokeAndWait {
fileManager.openFile(psiFile.virtualFile, false)
}
kotlin.test.assertNotNull<Any>(fileManager.currentFile) kotlin.test.assertNotNull<Any>(fileManager.currentFile)
typeText(commandToKeys("qa")) typeText(commandToKeys("qa"))
@ -36,7 +39,9 @@ class ExitCommandTest : VimTestCase() {
} }
@Suppress("IdeaVimAssertState") @Suppress("IdeaVimAssertState")
val psiFile = fixture.configureByText("A_Discovery", "Lorem ipsum dolor sit amet,") val psiFile = fixture.configureByText("A_Discovery", "Lorem ipsum dolor sit amet,")
fileManager.openFile(psiFile.virtualFile, false) ApplicationManager.getApplication().invokeAndWait {
fileManager.openFile(psiFile.virtualFile, false)
}
kotlin.test.assertNotNull<Any>(fileManager.currentFile) kotlin.test.assertNotNull<Any>(fileManager.currentFile)
typeText(commandToKeys("qall")) typeText(commandToKeys("qall"))
@ -51,8 +56,10 @@ class ExitCommandTest : VimTestCase() {
} }
val psiFile1 = fixture.configureByText("A_Discovery1", "Lorem ipsum dolor sit amet,") val psiFile1 = fixture.configureByText("A_Discovery1", "Lorem ipsum dolor sit amet,")
val psiFile2 = fixture.configureByText("A_Discovery2", "consectetur adipiscing elit") val psiFile2 = fixture.configureByText("A_Discovery2", "consectetur adipiscing elit")
fileManager.openFile(psiFile1.virtualFile, false) ApplicationManager.getApplication().invokeAndWait {
fileManager.openFile(psiFile2.virtualFile, false) fileManager.openFile(psiFile1.virtualFile, false)
fileManager.openFile(psiFile2.virtualFile, false)
}
kotlin.test.assertNotNull<Any>(fileManager.currentFile) kotlin.test.assertNotNull<Any>(fileManager.currentFile)
typeText(commandToKeys("qa")) typeText(commandToKeys("qa"))

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.api.options import com.maddyhome.idea.vim.api.options
@ -316,7 +317,9 @@ class GlobalCommandTest : VimTestCase() {
fun `test print multiple matching line if no command with number option`() { fun `test print multiple matching line if no command with number option`() {
configureByText(initialText) configureByText(initialText)
val editor = fixture.editor.vim val editor = fixture.editor.vim
injector.options(editor).number = true ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = true
}
typeText(commandToKeys(":g/it")) typeText(commandToKeys(":g/it"))
assertExOutput( assertExOutput(
""" """
@ -325,7 +328,9 @@ class GlobalCommandTest : VimTestCase() {
|5 where it was settled on some sodden sand |5 where it was settled on some sodden sand
""".trimMargin() """.trimMargin()
) )
injector.options(editor).number = false ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = false
}
} }
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT) @TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@ -348,14 +353,18 @@ class GlobalCommandTest : VimTestCase() {
fun `test print matching lines if no command and no trailing separator with number option`() { fun `test print matching lines if no command and no trailing separator with number option`() {
configureByText(initialText) configureByText(initialText)
val editor = fixture.editor.vim val editor = fixture.editor.vim
injector.options(editor).number = true ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = true
}
typeText(commandToKeys(":g/found/")) typeText(commandToKeys(":g/found/"))
assertExOutput( assertExOutput(
""" """
g/found/ g/found/
3 I found it in a legendary land""".trimIndent() 3 I found it in a legendary land""".trimIndent()
) )
injector.options(editor).number = false ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = false
}
} }
@Test @Test

View File

@ -1049,7 +1049,7 @@ class MapCommandTest : VimTestCase() {
typeText("k") typeText("k")
} }
} }
assertEquals(ExceptionHandler.exceptionMessage, exception.cause!!.cause!!.message) assertEquals(ExceptionHandler.exceptionMessage, exception.cause!!.cause!!.cause!!.message)
assertTrue(KeyHandler.getInstance().keyStack.isEmpty()) assertTrue(KeyHandler.getInstance().keyStack.isEmpty())
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.api.options import com.maddyhome.idea.vim.api.options
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
@ -78,7 +79,9 @@ class PrintCommandTest : VimTestCase() {
fun `test moves caret to start of last line of range skipping whitespace with number option`() { fun `test moves caret to start of last line of range skipping whitespace with number option`() {
configureByText(initialText) configureByText(initialText)
val editor = fixture.editor.vim val editor = fixture.editor.vim
injector.options(editor).number = true ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = true
}
typeText(commandToKeys("2,5p")) typeText(commandToKeys("2,5p"))
assertExOutput( assertExOutput(
""" """
@ -88,7 +91,9 @@ class PrintCommandTest : VimTestCase() {
|5 Sed in orci mauris. |5 Sed in orci mauris.
""".trimMargin(), """.trimMargin(),
) )
injector.options(editor).number = false ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = false
}
} }
@Test @Test

View File

@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.extension
import com.intellij.ide.plugins.PluginManagerCore import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Disposer
import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.PlatformTestUtil
@ -182,11 +183,15 @@ class OpMappingTest : VimTestCase() {
fun `test delayed action`() { fun `test delayed action`() {
configureByText("${c}I found it in a legendary land") configureByText("${c}I found it in a legendary land")
typeText("R") typeText("R")
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
assertState("I fou${c}nd it in a legendary land") assertState("I fou${c}nd it in a legendary land")
typeText("dR") typeText("dR")
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
assertState("I fou$c in a legendary land") assertState("I fou$c in a legendary land")
} }
@ -197,11 +202,15 @@ class OpMappingTest : VimTestCase() {
fun `test delayed incorrect action`() { fun `test delayed incorrect action`() {
configureByText("${c}I found it in a legendary land") configureByText("${c}I found it in a legendary land")
typeText("E") typeText("E")
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
assertState("I fou${c}nd it in a legendary land") assertState("I fou${c}nd it in a legendary land")
typeText("dE") typeText("dE")
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
assertState("I found it$c in a legendary land") assertState("I found it$c in a legendary land")
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.extension.multiplecursors package org.jetbrains.plugins.ideavim.extension.multiplecursors
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.state.mode.Mode
@ -189,7 +190,9 @@ class VimMultipleCursorsExtensionTest : VimTestCase() {
|dfkjsg |dfkjsg
""".trimMargin() """.trimMargin()
val editor = configureByText(before) val editor = configureByText(before)
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().invokeAndWait {
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("<A-p>")) typeText(injector.parser.parseKeys("<A-p>"))
@ -272,7 +275,9 @@ class VimMultipleCursorsExtensionTest : VimTestCase() {
|dfkjsg |dfkjsg
""".trimMargin() """.trimMargin()
val editor = configureByText(before) val editor = configureByText(before)
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().invokeAndWait {
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("<A-x>")) typeText(injector.parser.parseKeys("<A-x>"))
assertMode(Mode.VISUAL(SelectionType.CHARACTER_WISE)) assertMode(Mode.VISUAL(SelectionType.CHARACTER_WISE))
@ -362,7 +367,9 @@ fun getCellType(${s}pos$se: VisualPosition): CellType {
fun `test ignores regex in search pattern`() { fun `test ignores regex in search pattern`() {
val before = "test ${s}t.*st${c}$se toast tallest t.*st" val before = "test ${s}t.*st${c}$se toast tallest t.*st"
val editor = configureByText(before) val editor = configureByText(before)
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE) ApplicationManager.getApplication().invokeAndWait {
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("<A-n><A-n>")) typeText(injector.parser.parseKeys("<A-n><A-n>"))
val after = "test ${s}t.*st$se toast tallest ${s}t.*st$se" val after = "test ${s}t.*st$se toast tallest ${s}t.*st$se"

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.extension.replacewithregister package org.jetbrains.plugins.ideavim.extension.replacewithregister
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
@ -50,8 +51,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
configureByText(text) configureByText(text)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("griw")) typeText(injector.parser.parseKeys("griw"))
assertState("one on${c}e three") assertState("one on${c}e three")
val registerService = injector.registerGroup val registerService = injector.registerGroup
@ -177,8 +180,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("3griw")) typeText(injector.parser.parseKeys("3griw"))
assertState("one on${c}e four") assertState("one on${c}e four")
assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text) assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text)
@ -193,8 +198,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("griw")) typeText(injector.parser.parseKeys("griw"))
assertState("one two one four") assertState("one two one four")
assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text) assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text)
@ -208,8 +215,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false) VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("griw" + "w" + ".")) typeText(injector.parser.parseKeys("griw" + "w" + "."))
assertState("one one on${c}e four") assertState("one one on${c}e four")
assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text) assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text)
@ -260,8 +269,8 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText( VimPlugin.getRegister().storeText(
vimEditor, vimEditor,
context, context,
vimEditor.primaryCaret(), vimEditor.primaryCaret(),
@ -269,6 +278,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
SelectionType.CHARACTER_WISE, SelectionType.CHARACTER_WISE,
false false
) )
}
typeText(injector.parser.parseKeys("grr")) typeText(injector.parser.parseKeys("grr"))
assertState( assertState(
""" """
@ -436,15 +446,17 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup val registerService = injector.registerGroup
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText( VimPlugin.getRegister()
vimEditor, .storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
text rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, text rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("viw" + "gr")) typeText(injector.parser.parseKeys("viw" + "gr"))
assertState( assertState(
""" """
@ -515,15 +527,17 @@ class ReplaceWithRegisterTest : VimTestCase() {
configureByText(text) configureByText(text)
val vimEditor = fixture.editor.vim val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor) val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
VimPlugin.getRegister() ApplicationManager.getApplication().runReadAction {
.storeText( VimPlugin.getRegister()
vimEditor, .storeText(
context, vimEditor,
vimEditor.primaryCaret(), context,
text rangeOf "legendary", vimEditor.primaryCaret(),
SelectionType.CHARACTER_WISE, text rangeOf "legendary",
false SelectionType.CHARACTER_WISE,
) false
)
}
typeText(injector.parser.parseKeys("V" + "gr")) typeText(injector.parser.parseKeys("V" + "gr"))
assertState( assertState(
""" """

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.group package org.jetbrains.plugins.ideavim.group
import com.intellij.idea.TestFor import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.Ref import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.motion.search.SearchWholeWordForwardAction import com.maddyhome.idea.vim.action.motion.search.SearchWholeWordForwardAction
@ -915,16 +916,20 @@ class SearchGroupTest : VimTestCase() {
val project = fixture.project val project = fixture.project
val searchGroup = VimPlugin.getSearch() val searchGroup = VimPlugin.getSearch()
val ref = Ref.create(-1) val ref = Ref.create(-1)
RunnableHelper.runReadCommand( ApplicationManager.getApplication().invokeAndWait {
project, ApplicationManager.getApplication().runWriteIntentReadAction<Any, Throwable> {
{ RunnableHelper.runReadCommand(
// Does not move the caret! project,
val n = searchGroup.processSearchCommand(editor.vim, pattern, fixture.caretOffset, 1, Direction.FORWARDS) {
ref.set(n?.first ?: -1) // Does not move the caret!
}, val n = searchGroup.processSearchCommand(editor.vim, pattern, fixture.caretOffset, 1, Direction.FORWARDS)
null, ref.set(n?.first ?: -1)
null, },
) null,
null,
)
}
}
return ref.get() return ref.get()
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.group.motion package org.jetbrains.plugins.ideavim.group.motion
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.helper.EditorHelper import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -106,9 +107,11 @@ class MotionGroup_ScrollCaretIntoViewHorizontally_Test : VimTestCase() {
typeText("100|", "20l") typeText("100|", "20l")
// These columns are hard to calculate, because the visible offset depends on the rendered width of the inlay // These columns are hard to calculate, because the visible offset depends on the rendered width of the inlay
// Also, because we're scrolling right (adding columns to the right) we make the right most column line up // Also, because we're scrolling right (adding columns to the right) we make the right most column line up
val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels ApplicationManager.getApplication().invokeAndWait {
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt() val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels
assertVisibleLineBounds(0, 119 - availableColumns + 1, 119) val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
assertVisibleLineBounds(0, 119 - availableColumns + 1, 119)
}
} }
@TestWithoutNeovim(reason = SkipNeovimReason.SCROLL) @TestWithoutNeovim(reason = SkipNeovimReason.SCROLL)
@ -190,9 +193,11 @@ class MotionGroup_ScrollCaretIntoViewHorizontally_Test : VimTestCase() {
val inlay = addInlay(110, true, 5) val inlay = addInlay(110, true, 5)
typeText("120|zs", "20h") typeText("120|zs", "20h")
// These columns are hard to calculate, because the visible offset depends on the rendered width of the inlay // These columns are hard to calculate, because the visible offset depends on the rendered width of the inlay
val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels ApplicationManager.getApplication().invokeAndWait {
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt() val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1) val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
}
} }
@TestWithoutNeovim(reason = SkipNeovimReason.SCROLL) @TestWithoutNeovim(reason = SkipNeovimReason.SCROLL)

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.group.motion package org.jetbrains.plugins.ideavim.group.motion
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.helper.EditorHelper import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -255,6 +256,8 @@ class MotionGroup_ScrollCaretIntoViewVertically_Test : VimTestCase() {
} }
private fun assertVisualLineAtMiddleOfScreen(expected: Int) { private fun assertVisualLineAtMiddleOfScreen(expected: Int) {
kotlin.test.assertEquals(expected, EditorHelper.getVisualLineAtMiddleOfScreen(fixture.editor)) ApplicationManager.getApplication().invokeAndWait {
kotlin.test.assertEquals(expected, EditorHelper.getVisualLineAtMiddleOfScreen(fixture.editor))
}
} }
} }

View File

@ -13,6 +13,7 @@ package org.jetbrains.plugins.ideavim.group.visual
import com.intellij.codeInsight.template.TemplateManager import com.intellij.codeInsight.template.TemplateManager
import com.intellij.codeInsight.template.impl.ConstantNode import com.intellij.codeInsight.template.impl.ConstantNode
import com.intellij.codeInsight.template.impl.TemplateManagerImpl import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.visual.IdeaSelectionControl import com.maddyhome.idea.vim.group.visual.IdeaSelectionControl
import com.maddyhome.idea.vim.group.visual.VimVisualTimer import com.maddyhome.idea.vim.group.visual.VimVisualTimer
@ -691,7 +692,9 @@ class IdeaVisualControlTest : VimTestCase() {
VimListenerManager.EditorListeners.addAll() VimListenerManager.EditorListeners.addAll()
assertMode(Mode.NORMAL()) assertMode(Mode.NORMAL())
fixture.editor.selectionModel.setSelection(5, 10) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(5, 10)
}
waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE))
} }
@ -710,7 +713,9 @@ class IdeaVisualControlTest : VimTestCase() {
VimListenerManager.EditorListeners.addAll() VimListenerManager.EditorListeners.addAll()
assertMode(Mode.NORMAL()) assertMode(Mode.NORMAL())
fixture.editor.selectionModel.setSelection(5, 10) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(5, 10)
}
waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE))
} }
@ -729,7 +734,9 @@ class IdeaVisualControlTest : VimTestCase() {
typeText(injector.parser.parseKeys("V")) typeText(injector.parser.parseKeys("V"))
assertMode(Mode.VISUAL(SelectionType.LINE_WISE)) assertMode(Mode.VISUAL(SelectionType.LINE_WISE))
fixture.editor.selectionModel.setSelection(2, 5) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(2, 5)
}
IdeaSelectionControl.controlNonVimSelectionChange(fixture.editor) IdeaSelectionControl.controlNonVimSelectionChange(fixture.editor)
waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.CHARACTER_WISE } waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.CHARACTER_WISE }
@ -751,17 +758,21 @@ class IdeaVisualControlTest : VimTestCase() {
startDummyTemplate() startDummyTemplate()
VimVisualTimer.doNow() ApplicationManager.getApplication().invokeAndWait {
VimVisualTimer.doNow()
}
typeText(injector.parser.parseKeys("<esc>V")) typeText(injector.parser.parseKeys("<esc>V"))
assertMode(Mode.VISUAL(SelectionType.LINE_WISE)) assertMode(Mode.VISUAL(SelectionType.LINE_WISE))
fixture.editor.selectionModel.setSelection(2, 5) ApplicationManager.getApplication().invokeAndWait {
IdeaSelectionControl.controlNonVimSelectionChange(fixture.editor) fixture.editor.selectionModel.setSelection(2, 5)
IdeaSelectionControl.controlNonVimSelectionChange(fixture.editor)
waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.CHARACTER_WISE } waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.CHARACTER_WISE }
assertMode(Mode.VISUAL(SelectionType.CHARACTER_WISE)) assertMode(Mode.VISUAL(SelectionType.CHARACTER_WISE))
assertCaretsVisualAttributes() assertCaretsVisualAttributes()
}
} }
@OptionTest(VimOption(TestOptionConstants.selectmode, limitedValues = [""])) @OptionTest(VimOption(TestOptionConstants.selectmode, limitedValues = [""]))
@ -782,10 +793,14 @@ class IdeaVisualControlTest : VimTestCase() {
} }
private fun startDummyTemplate() { private fun startDummyTemplate() {
TemplateManagerImpl.setTemplateTesting(fixture.testRootDisposable) ApplicationManager.getApplication().invokeAndWait {
val templateManager = TemplateManager.getInstance(fixture.project) ApplicationManager.getApplication().runWriteIntentReadAction<Any, Throwable> {
val createdTemplate = templateManager.createTemplate("", "") TemplateManagerImpl.setTemplateTesting(fixture.testRootDisposable)
createdTemplate.addVariable(ConstantNode("1"), true) val templateManager = TemplateManager.getInstance(fixture.project)
templateManager.startTemplate(fixture.editor, createdTemplate) val createdTemplate = templateManager.createTemplate("", "")
createdTemplate.addVariable(ConstantNode("1"), true)
templateManager.startTemplate(fixture.editor, createdTemplate)
}
}
} }
} }

View File

@ -47,9 +47,11 @@ class NonVimVisualChangeTest : VimTestCase() {
) )
typeText("i") typeText("i")
assertMode(Mode.INSERT) assertMode(Mode.INSERT)
ApplicationManager.getApplication().runWriteAction { ApplicationManager.getApplication().invokeAndWait {
CommandProcessor.getInstance().runUndoTransparentAction { ApplicationManager.getApplication().runWriteAction {
BackspaceHandler.deleteToTargetPosition(fixture.editor, LogicalPosition(2, 0)) CommandProcessor.getInstance().runUndoTransparentAction {
BackspaceHandler.deleteToTargetPosition(fixture.editor, LogicalPosition(2, 0))
}
} }
} }
assertState( assertState(
@ -82,8 +84,10 @@ class NonVimVisualChangeTest : VimTestCase() {
assertMode(Mode.INSERT) assertMode(Mode.INSERT)
// Fast add and remove selection // Fast add and remove selection
fixture.editor.selectionModel.setSelection(0, 10) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.removeSelection() fixture.editor.selectionModel.setSelection(0, 10)
fixture.editor.selectionModel.removeSelection()
}
assertDoesntChange { fixture.editor.vim.mode == Mode.INSERT } assertDoesntChange { fixture.editor.vim.mode == Mode.INSERT }
} }
@ -105,9 +109,11 @@ class NonVimVisualChangeTest : VimTestCase() {
assertMode(Mode.INSERT) assertMode(Mode.INSERT)
// Fast add and remove selection // Fast add and remove selection
fixture.editor.selectionModel.setSelection(0, 10) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.removeSelection() fixture.editor.selectionModel.setSelection(0, 10)
fixture.editor.selectionModel.setSelection(0, 10) fixture.editor.selectionModel.removeSelection()
fixture.editor.selectionModel.setSelection(0, 10)
}
waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE))
} }
@ -128,12 +134,16 @@ class NonVimVisualChangeTest : VimTestCase() {
assertMode(Mode.INSERT) assertMode(Mode.INSERT)
val range = text.rangeOf("Discovery") val range = text.rangeOf("Discovery")
fixture.editor.selectionModel.setSelection(range.startOffset, range.endOffset) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(range.startOffset, range.endOffset)
}
waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE)) waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE))
assertEquals(SelectionType.CHARACTER_WISE, fixture.editor.vim.mode.selectionType) assertEquals(SelectionType.CHARACTER_WISE, fixture.editor.vim.mode.selectionType)
val rangeLine = text.rangeOf("A Discovery\n") val rangeLine = text.rangeOf("A Discovery\n")
fixture.editor.selectionModel.setSelection(rangeLine.startOffset, rangeLine.endOffset) ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(rangeLine.startOffset, rangeLine.endOffset)
}
waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.LINE_WISE } waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.LINE_WISE }
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.helper package org.jetbrains.plugins.ideavim.helper
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Caret import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.CaretVisualAttributes import com.intellij.openapi.editor.CaretVisualAttributes
import com.intellij.openapi.editor.VisualPosition import com.intellij.openapi.editor.VisualPosition
@ -330,9 +331,11 @@ class CaretVisualAttributesHelperTest : VimTestCase() {
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING) @TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@Test @Test
fun `test adding new caret via IJ`() { fun `test adding new caret via IJ`() {
configureByText("${c}Lorem ipsum dolor sit amet,") ApplicationManager.getApplication().invokeAndWait {
fixture.editor.caretModel.addCaret(VisualPosition(0, 5)) configureByText("${c}Lorem ipsum dolor sit amet,")
assertCaretVisualAttributes(CaretVisualAttributes.Shape.BLOCK, 0f) fixture.editor.caretModel.addCaret(VisualPosition(0, 5))
assertCaretVisualAttributes(CaretVisualAttributes.Shape.BLOCK, 0f)
}
} }
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING) @TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@ -344,13 +347,15 @@ class CaretVisualAttributesHelperTest : VimTestCase() {
|consectetur adipiscing elit |consectetur adipiscing elit
""".trimMargin(), """.trimMargin(),
) )
injector.actionExecutor.executeAction( ApplicationManager.getApplication().invokeAndWait {
fixture.editor.vim, injector.actionExecutor.executeAction(
name = "EditorCloneCaretBelow", fixture.editor.vim,
context = injector.executionContextManager.getEditorExecutionContext(fixture.editor.vim), name = "EditorCloneCaretBelow",
) context = injector.executionContextManager.getEditorExecutionContext(fixture.editor.vim),
kotlin.test.assertEquals(2, fixture.editor.caretModel.caretCount) )
assertCaretVisualAttributes(CaretVisualAttributes.Shape.BLOCK, 0f) kotlin.test.assertEquals(2, fixture.editor.caretModel.caretCount)
assertCaretVisualAttributes(CaretVisualAttributes.Shape.BLOCK, 0f)
}
} }
private fun assertCaretVisualAttributes(expectedShape: CaretVisualAttributes.Shape, expectedThickness: Float) { private fun assertCaretVisualAttributes(expectedShape: CaretVisualAttributes.Shape, expectedThickness: Float) {

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.helper package org.jetbrains.plugins.ideavim.helper
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.helper.EditorHelper import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.SkipNeovimReason import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -21,10 +22,12 @@ class EditorHelperTest : VimTestCase() {
@Test @Test
fun `test scroll column to left of screen`() { fun `test scroll column to left of screen`() {
configureByColumns(100) configureByColumns(100)
EditorHelper.scrollColumnToLeftOfScreen(fixture.editor, 0, 2) ApplicationManager.getApplication().invokeAndWait {
val visibleArea = fixture.editor.scrollingModel.visibleArea EditorHelper.scrollColumnToLeftOfScreen(fixture.editor, 0, 2)
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor) val visibleArea = fixture.editor.scrollingModel.visibleArea
assertEquals((2 * columnWidth).roundToInt(), visibleArea.x) val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals((2 * columnWidth).roundToInt(), visibleArea.x)
}
} }
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING) @TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@ -32,10 +35,12 @@ class EditorHelperTest : VimTestCase() {
fun `test scroll column to right of screen`() { fun `test scroll column to right of screen`() {
configureByColumns(100) configureByColumns(100)
val column = screenWidth + 2 val column = screenWidth + 2
EditorHelper.scrollColumnToRightOfScreen(fixture.editor, 0, column) ApplicationManager.getApplication().invokeAndWait {
val visibleArea = fixture.editor.scrollingModel.visibleArea EditorHelper.scrollColumnToRightOfScreen(fixture.editor, 0, column)
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor) val visibleArea = fixture.editor.scrollingModel.visibleArea
assertEquals(((column - screenWidth + 1) * columnWidth).roundToInt(), visibleArea.x) val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals(((column - screenWidth + 1) * columnWidth).roundToInt(), visibleArea.x)
}
} }
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING) @TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@ -45,10 +50,12 @@ class EditorHelperTest : VimTestCase() {
// For an 80 column screen, moving a column to the centre should position it in column 41 (1 based) - 40 columns on // For an 80 column screen, moving a column to the centre should position it in column 41 (1 based) - 40 columns on
// the left, mid point, 39 columns on the right // the left, mid point, 39 columns on the right
// Put column 100 into position 41 -> offset is 59 columns // Put column 100 into position 41 -> offset is 59 columns
EditorHelper.scrollColumnToMiddleOfScreen(fixture.editor, 0, 99) ApplicationManager.getApplication().invokeAndWait {
val visibleArea = fixture.editor.scrollingModel.visibleArea EditorHelper.scrollColumnToMiddleOfScreen(fixture.editor, 0, 99)
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor) val visibleArea = fixture.editor.scrollingModel.visibleArea
assertEquals((59 * columnWidth).roundToInt(), visibleArea.x) val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals((59 * columnWidth).roundToInt(), visibleArea.x)
}
} }
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING) @TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@ -59,9 +66,11 @@ class EditorHelperTest : VimTestCase() {
// For an 81 column screen, moving a column to the centre should position it in column 41 (1 based) - 40 columns on // For an 81 column screen, moving a column to the centre should position it in column 41 (1 based) - 40 columns on
// the left, mid point, 40 columns on the right // the left, mid point, 40 columns on the right
// Put column 100 into position 41 -> offset is 59 columns // Put column 100 into position 41 -> offset is 59 columns
EditorHelper.scrollColumnToMiddleOfScreen(fixture.editor, 0, 99) ApplicationManager.getApplication().invokeAndWait {
val visibleArea = fixture.editor.scrollingModel.visibleArea EditorHelper.scrollColumnToMiddleOfScreen(fixture.editor, 0, 99)
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor) val visibleArea = fixture.editor.scrollingModel.visibleArea
assertEquals((59 * columnWidth).roundToInt(), visibleArea.x) val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals((59 * columnWidth).roundToInt(), visibleArea.x)
}
} }
} }

View File

@ -7,6 +7,7 @@
*/ */
package org.jetbrains.plugins.ideavim.helper package org.jetbrains.plugins.ideavim.helper
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.findBlockRange import com.maddyhome.idea.vim.group.findBlockRange
@ -104,8 +105,10 @@ class SearchHelperTest : VimTestCase() {
fun findBlockRange(testCase: FindBlockRangeTestCase) { fun findBlockRange(testCase: FindBlockRangeTestCase) {
val (_, text, type, count, isOuter, expected) = (testCase) val (_, text, type, count, isOuter, expected) = (testCase)
configureByText(text) configureByText(text)
val actual = findBlockRange(fixture.editor.vim, fixture.editor.vim.currentCaret(), type, count, isOuter) ApplicationManager.getApplication().runReadAction {
kotlin.test.assertEquals(expected, actual) val actual = findBlockRange(fixture.editor.vim, fixture.editor.vim.currentCaret(), type, count, isOuter)
kotlin.test.assertEquals(expected, actual)
}
} }
companion object { companion object {

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.listener package org.jetbrains.plugins.ideavim.listener
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ComponentManagerEx import com.intellij.openapi.components.ComponentManagerEx
import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
@ -66,7 +67,9 @@ class VimListenersTest : VimTestCase() {
configureByText("XYZ") configureByText("XYZ")
val fileManager = FileEditorManagerEx.getInstanceEx(fixture.project) val fileManager = FileEditorManagerEx.getInstanceEx(fixture.project)
fileManager.closeFile(fixture.editor.virtualFile) ApplicationManager.getApplication().invokeAndWait {
fileManager.closeFile(fixture.editor.virtualFile)
}
assertEquals(1, VimListenerTestObject.disposedCounter) assertEquals(1, VimListenerTestObject.disposedCounter)
} }
@ -80,7 +83,9 @@ class VimListenersTest : VimTestCase() {
assertEquals(1, VimListenerTestObject.disposedCounter) assertEquals(1, VimListenerTestObject.disposedCounter)
val fileManager = FileEditorManagerEx.getInstanceEx(fixture.project) val fileManager = FileEditorManagerEx.getInstanceEx(fixture.project)
fileManager.closeFile(fixture.editor.virtualFile) ApplicationManager.getApplication().invokeAndWait {
fileManager.closeFile(fixture.editor.virtualFile)
}
assertEquals(1, VimListenerTestObject.disposedCounter) assertEquals(1, VimListenerTestObject.disposedCounter)
} finally { } finally {

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -38,7 +39,9 @@ class BreakIndentOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -172,7 +175,11 @@ class BreakIndentOptionMapperTest : VimTestCase() {
fun `test setting global IDE value will update effective Vim value set during plugin startup`() { fun `test setting global IDE value will update effective Vim value set during plugin startup`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default // Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isUseCustomSoftWrapIndent = true EditorSettingsExternalizable.getInstance().isUseCustomSoftWrapIndent = true
injector.optionGroup.resetAllOptionsForTesting() ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()
@ -293,7 +300,11 @@ class BreakIndentOptionMapperTest : VimTestCase() {
fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() { fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default // Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isUseCustomSoftWrapIndent = true EditorSettingsExternalizable.getInstance().isUseCustomSoftWrapIndent = true
injector.optionGroup.resetAllOptionsForTesting() ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()

View File

@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.application.options.CodeStyle import com.intellij.application.options.CodeStyle
import com.intellij.lang.Language import com.intellij.lang.Language
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.impl.SettingsImpl import com.intellij.openapi.editor.impl.SettingsImpl
@ -42,7 +43,9 @@ class ColorColumnOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun openNewBufferWindow(filename: String, content: String): Editor { private fun openNewBufferWindow(filename: String, content: String): Editor {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -100,93 +103,109 @@ class ColorColumnOptionMapperTest : VimTestCase() {
fun `test 'colorcolumn' reports '+0' to show right margin is visible`() { fun `test 'colorcolumn' reports '+0' to show right margin is visible`() {
// IntelliJ only has one setting for visual guides and hard-wrap typing margin, so we have to report a special value // IntelliJ only has one setting for visual guides and hard-wrap typing margin, so we have to report a special value
// of "+0", which makes Vim show a highlight column at 'textwidth' (IntelliJ shows it even if 'textwidth' is 0) // of "+0", which makes Vim show a highlight column at 'textwidth' (IntelliJ shows it even if 'textwidth' is 0)
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set colorcolumn?", " colorcolumn=+0") fixture.editor.settings.isRightMarginShown = true
assertCommandOutput("set colorcolumn?", " colorcolumn=+0")
}
} }
@Test @Test
fun `test 'colorcolumn' reports '+0' at end of visual guide list`() { fun `test 'colorcolumn' reports '+0' at end of visual guide list`() {
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) fixture.editor.settings.isRightMarginShown = true
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0") fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
}
} }
@Test @Test
fun `test 'colorcolumn' option reports global intellij setting if not explicitly set`() { fun `test 'colorcolumn' option reports global intellij setting if not explicitly set`() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
setGlobalSoftMargins(listOf(10, 20, 30)) EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0") setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
setGlobalSoftMargins(listOf(90, 80, 70)) setGlobalSoftMargins(listOf(90, 80, 70))
assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0")
setGlobalSoftMargins(emptyList()) setGlobalSoftMargins(emptyList())
assertCommandOutput("set colorcolumn?", " colorcolumn=+0") assertCommandOutput("set colorcolumn?", " colorcolumn=+0")
EditorSettingsExternalizable.getInstance().isRightMarginShown = false EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=") assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
fun `test local 'colorcolumn' option reports global intellij setting if not explicitly set`() { fun `test local 'colorcolumn' option reports global intellij setting if not explicitly set`() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
setGlobalSoftMargins(listOf(10, 20, 30)) EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=10,20,30,+0") setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=10,20,30,+0")
setGlobalSoftMargins(listOf(90, 80, 70)) setGlobalSoftMargins(listOf(90, 80, 70))
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0")
setGlobalSoftMargins(emptyList()) setGlobalSoftMargins(emptyList())
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=+0") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=+0")
EditorSettingsExternalizable.getInstance().isRightMarginShown = false EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
fun `test 'colorcolumn' option reports local intellij setting if set via IDE`() { fun `test 'colorcolumn' option reports local intellij setting if set via IDE`() {
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) fixture.editor.settings.isRightMarginShown = true
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0") fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
fixture.editor.settings.setSoftMargins(listOf(70, 80, 90)) fixture.editor.settings.setSoftMargins(listOf(70, 80, 90))
assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0")
fixture.editor.settings.setSoftMargins(emptyList()) fixture.editor.settings.setSoftMargins(emptyList())
assertCommandOutput("set colorcolumn?", " colorcolumn=+0") assertCommandOutput("set colorcolumn?", " colorcolumn=+0")
fixture.editor.settings.isRightMarginShown = false fixture.editor.settings.isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=") assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
fun `test local 'colorcolumn' option reports local intellij setting if set via IDE`() { fun `test local 'colorcolumn' option reports local intellij setting if set via IDE`() {
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) fixture.editor.settings.isRightMarginShown = true
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=10,20,30,+0") fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=10,20,30,+0")
fixture.editor.settings.setSoftMargins(listOf(70, 80, 90)) fixture.editor.settings.setSoftMargins(listOf(70, 80, 90))
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0")
fixture.editor.settings.setSoftMargins(emptyList()) fixture.editor.settings.setSoftMargins(emptyList())
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=+0") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=+0")
fixture.editor.settings.isRightMarginShown = false fixture.editor.settings.isRightMarginShown = false
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
fun `test 'colorcolumn' does not report current visual guides if global right margin option is disabled`() { fun `test 'colorcolumn' does not report current visual guides if global right margin option is disabled`() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = false ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=") fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
fun `test 'colorcolumn' does not report current visual guides if local right margin option is disabled`() { fun `test 'colorcolumn' does not report current visual guides if local right margin option is disabled`() {
fixture.editor.settings.isRightMarginShown = false ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) fixture.editor.settings.isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=") fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
@ -260,8 +279,10 @@ class ColorColumnOptionMapperTest : VimTestCase() {
fun `test setting IDE value is treated like setlocal`() { fun `test setting IDE value is treated like setlocal`() {
// If we use `:set`, it updates the local and per-window global values. If we set the value from the IDE, it only // If we use `:set`, it updates the local and per-window global values. If we set the value from the IDE, it only
// affects the local value // affects the local value
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(70, 80, 90)) fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(70, 80, 90))
}
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0")
assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0")
assertCommandOutput("setglobal colorcolumn?", " colorcolumn=") assertCommandOutput("setglobal colorcolumn?", " colorcolumn=")
@ -282,66 +303,74 @@ class ColorColumnOptionMapperTest : VimTestCase() {
@Test @Test
fun `test reset 'colorcolun' to default copies current global intellij setting`() { fun `test reset 'colorcolun' to default copies current global intellij setting`() {
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
enterCommand("set colorcolumn&") enterCommand("set colorcolumn&")
assertCommandOutput("set colorcolumn?", " colorcolumn=") assertCommandOutput("set colorcolumn?", " colorcolumn=")
assertFalse(fixture.editor.settings.isRightMarginShown) assertFalse(fixture.editor.settings.isRightMarginShown)
assertEmpty(fixture.editor.settings.softMargins) assertEmpty(fixture.editor.settings.softMargins)
// Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the global value // Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the global value
EditorSettingsExternalizable.getInstance().isRightMarginShown = true EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertFalse(fixture.editor.settings.isRightMarginShown) assertFalse(fixture.editor.settings.isRightMarginShown)
}
} }
@Test @Test
fun `test reset local 'colorcolun' to default copies current global intellij setting`() { fun `test reset local 'colorcolun' to default copies current global intellij setting`() {
fixture.editor.settings.isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30)) fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
enterCommand("setlocal colorcolumn&") enterCommand("setlocal colorcolumn&")
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=") assertCommandOutput("setlocal colorcolumn?", " colorcolumn=")
assertFalse(fixture.editor.settings.isRightMarginShown) assertFalse(fixture.editor.settings.isRightMarginShown)
assertEmpty(fixture.editor.settings.softMargins) assertEmpty(fixture.editor.settings.softMargins)
// Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the global value // Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the global value
EditorSettingsExternalizable.getInstance().isRightMarginShown = true EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertFalse(fixture.editor.settings.isRightMarginShown) assertFalse(fixture.editor.settings.isRightMarginShown)
}
} }
@Test @Test
fun `test open new window without setting ideavim option will initialise 'colorcolumn' to defaults`() { fun `test open new window without setting ideavim option will initialise 'colorcolumn' to defaults`() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
setGlobalSoftMargins(listOf(10, 20, 30)) EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0") setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
openNewBufferWindow("bbb.txt", "lorem ipsum") openNewBufferWindow("bbb.txt", "lorem ipsum")
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
// Changing the global value should update the editor // Changing the global value should update the editor
setGlobalSoftMargins(listOf(40, 50, 60, 70)) setGlobalSoftMargins(listOf(40, 50, 60, 70))
assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,70,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,70,+0")
EditorSettingsExternalizable.getInstance().isRightMarginShown = false EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=") assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
} }
@Test @Test
fun `test open new window after setting ideavim option will initialise 'colorcolumn' to setglobal value`() { fun `test open new window after setting ideavim option will initialise 'colorcolumn' to setglobal value`() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true ApplicationManager.getApplication().invokeAndWait {
setGlobalSoftMargins(listOf(10, 20, 30)) EditorSettingsExternalizable.getInstance().isRightMarginShown = true
enterCommand("set colorcolumn=40,50,60") setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0") enterCommand("set colorcolumn=40,50,60")
assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0")
openNewBufferWindow("bbb.txt", "lorem ipsum") openNewBufferWindow("bbb.txt", "lorem ipsum")
assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0")
// Changing the global value should NOT update the editor // Changing the global value should NOT update the editor
setGlobalSoftMargins(listOf(10, 20, 30)) setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0") assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0")
}
} }
@Test @Test
@ -358,19 +387,25 @@ class ColorColumnOptionMapperTest : VimTestCase() {
} }
private fun getGlobalSoftMargins(): List<Int> { private fun getGlobalSoftMargins(): List<Int> {
val language = TextEditorImpl.getDocumentLanguage(fixture.editor) var res: List<Int>? = null
return CodeStyle.getSettings(fixture.editor).getSoftMargins(language) ApplicationManager.getApplication().runReadAction {
val language = TextEditorImpl.getDocumentLanguage(fixture.editor)
res = CodeStyle.getSettings(fixture.editor).getSoftMargins(language)
}
return res!!
} }
private fun setGlobalSoftMargins(margins: List<Int>) { private fun setGlobalSoftMargins(margins: List<Int>) {
val language = TextEditorImpl.getDocumentLanguage(fixture.editor) ApplicationManager.getApplication().runReadAction {
val commonSettings = CodeStyle.getSettings(fixture.editor).getCommonSettings(language) val language = TextEditorImpl.getDocumentLanguage(fixture.editor)
if (language == null || commonSettings.language == Language.ANY) { val commonSettings = CodeStyle.getSettings(fixture.editor).getCommonSettings(language)
CodeStyle.getSettings(fixture.editor).defaultSoftMargins = margins if (language == null || commonSettings.language == Language.ANY) {
} else { CodeStyle.getSettings(fixture.editor).defaultSoftMargins = margins
CodeStyle.getSettings(fixture.editor).setSoftMargins(language, margins) } else {
CodeStyle.getSettings(fixture.editor).setSoftMargins(language, margins)
}
// Setting the value directly doesn't invalidate the cached property value. Not sure if there's a better way
(fixture.editor.settings as SettingsImpl).reinitSettings()
} }
// Setting the value directly doesn't invalidate the cached property value. Not sure if there's a better way
(fixture.editor.settings as SettingsImpl).reinitSettings()
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.impl.SettingsImpl import com.intellij.openapi.editor.impl.SettingsImpl
import com.maddyhome.idea.vim.group.IjOptions import com.maddyhome.idea.vim.group.IjOptions
@ -32,7 +33,9 @@ class CursorLineOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -48,41 +51,51 @@ class CursorLineOptionMapperTest : VimTestCase() {
@Test @Test
fun `test 'cursorline' defaults to global intellij setting`() { fun `test 'cursorline' defaults to global intellij setting`() {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) } ApplicationManager.getApplication().invokeAndWait {
assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown) (fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
assertTrue(optionsIj().cursorline) assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown)
assertTrue(optionsIj().cursorline)
}
} }
@Test @Test
fun `test 'cursorline' option reports global intellij setting if not explicitly set`() { fun `test 'cursorline' option reports global intellij setting if not explicitly set`() {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) } ApplicationManager.getApplication().invokeAndWait {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
}
assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown) assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown)
assertCommandOutput("set cursorline?", " cursorline") assertCommandOutput("set cursorline?", " cursorline")
} }
@Test @Test
fun `test local 'cursorline' option reports global intellij setting if not explicitly set`() { fun `test local 'cursorline' option reports global intellij setting if not explicitly set`() {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) } ApplicationManager.getApplication().invokeAndWait {
assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown) (fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
assertCommandOutput("setlocal cursorline?", " cursorline") assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown)
assertCommandOutput("setlocal cursorline?", " cursorline")
}
} }
@Test @Test
fun `test 'cursorline' option reports local intellij setting if set via IDE`() { fun `test 'cursorline' option reports local intellij setting if set via IDE`() {
fixture.editor.settings.isCaretRowShown = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set cursorline?", "nocursorline") fixture.editor.settings.isCaretRowShown = false
assertCommandOutput("set cursorline?", "nocursorline")
fixture.editor.settings.isCaretRowShown = true fixture.editor.settings.isCaretRowShown = true
assertCommandOutput("set cursorline?", " cursorline") assertCommandOutput("set cursorline?", " cursorline")
}
} }
@Test @Test
fun `test local 'cursorline' option reports local intellij setting if set via IDE`() { fun `test local 'cursorline' option reports local intellij setting if set via IDE`() {
fixture.editor.settings.isCaretRowShown = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal cursorline?", "nocursorline") fixture.editor.settings.isCaretRowShown = false
assertCommandOutput("setlocal cursorline?", "nocursorline")
fixture.editor.settings.isCaretRowShown = true fixture.editor.settings.isCaretRowShown = true
assertCommandOutput("setlocal cursorline?", " cursorline") assertCommandOutput("setlocal cursorline?", " cursorline")
}
} }
@Test @Test
@ -184,14 +197,16 @@ class CursorLineOptionMapperTest : VimTestCase() {
fun `test open new window without setting the option copies value as not-explicitly set`() { fun `test open new window without setting the option copies value as not-explicitly set`() {
// New window will clone local and global local-to-window options, then apply global to local. This tests that our // New window will clone local and global local-to-window options, then apply global to local. This tests that our
// handling of per-window "global" values is correct. // handling of per-window "global" values is correct.
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) } ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set cursorline?", " cursorline") (fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
assertCommandOutput("set cursorline?", " cursorline")
switchToNewFile("bbb.txt", "lorem ipsum") switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set cursorline?", " cursorline") assertCommandOutput("set cursorline?", " cursorline")
// Can't prove that it was copied as a default value because we can't change the global value // Can't prove that it was copied as a default value because we can't change the global value
}
} }
@Test @Test

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.EditorSettings.LineNumerationType import com.intellij.openapi.editor.EditorSettings.LineNumerationType
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
@ -40,7 +41,9 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -64,26 +67,30 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Test @Test
fun `test 'number' and 'relativenumber' options reports global intellij setting if not explicitly set`() { fun `test 'number' and 'relativenumber' options reports global intellij setting if not explicitly set`() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set number?", "nonumber") EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("set relativenumber?", "norelativenumber") assertCommandOutput("set number?", "nonumber")
assertCommandOutput("set relativenumber?", "norelativenumber")
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.HYBRID EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.HYBRID
assertCommandOutput("set number?", " number") assertCommandOutput("set number?", " number")
assertCommandOutput("set relativenumber?", " relativenumber") assertCommandOutput("set relativenumber?", " relativenumber")
}
} }
@Test @Test
fun `test local 'number' and 'relativenumber' options reports global intellij setting if not explicitly set`() { fun `test local 'number' and 'relativenumber' options reports global intellij setting if not explicitly set`() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal number?", "nonumber") EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("setlocal relativenumber?", "norelativenumber") assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.HYBRID EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.HYBRID
assertCommandOutput("setlocal number?", " number") assertCommandOutput("setlocal number?", " number")
assertCommandOutput("setlocal relativenumber?", " relativenumber") assertCommandOutput("setlocal relativenumber?", " relativenumber")
}
} }
@Test @Test
@ -93,39 +100,43 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set relativenumber?", "norelativenumber") assertCommandOutput("set relativenumber?", "norelativenumber")
// View | Active Editor | Show Line Numbers. There is no UI for line numeration type // View | Active Editor | Show Line Numbers. There is no UI for line numeration type
fixture.editor.settings.isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID fixture.editor.settings.isLineNumbersShown = true
assertCommandOutput("set number?", " number") fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID
assertCommandOutput("set relativenumber?", " relativenumber") assertCommandOutput("set number?", " number")
assertCommandOutput("set relativenumber?", " relativenumber")
fixture.editor.settings.lineNumerationType = LineNumerationType.ABSOLUTE fixture.editor.settings.lineNumerationType = LineNumerationType.ABSOLUTE
assertCommandOutput("set number?", " number") assertCommandOutput("set number?", " number")
assertCommandOutput("set relativenumber?", "norelativenumber") assertCommandOutput("set relativenumber?", "norelativenumber")
fixture.editor.settings.lineNumerationType = LineNumerationType.RELATIVE fixture.editor.settings.lineNumerationType = LineNumerationType.RELATIVE
assertCommandOutput("set number?", "nonumber") assertCommandOutput("set number?", "nonumber")
assertCommandOutput("set relativenumber?", " relativenumber") assertCommandOutput("set relativenumber?", " relativenumber")
}
} }
@Test @Test
fun `test local 'number' and 'relativenumber' options report local intellij settings if set via IDE`() { fun `test local 'number' and 'relativenumber' options report local intellij settings if set via IDE`() {
fixture.editor.settings.isLineNumbersShown = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal number?", "nonumber") fixture.editor.settings.isLineNumbersShown = false
assertCommandOutput("setlocal relativenumber?", "norelativenumber") assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
// View | Active Editor | Show Line Numbers. There is no UI for line numeration type // View | Active Editor | Show Line Numbers. There is no UI for line numeration type
fixture.editor.settings.isLineNumbersShown = true fixture.editor.settings.isLineNumbersShown = true
fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID
assertCommandOutput("setlocal number?", " number") assertCommandOutput("setlocal number?", " number")
assertCommandOutput("setlocal relativenumber?", " relativenumber") assertCommandOutput("setlocal relativenumber?", " relativenumber")
fixture.editor.settings.lineNumerationType = LineNumerationType.ABSOLUTE fixture.editor.settings.lineNumerationType = LineNumerationType.ABSOLUTE
assertCommandOutput("setlocal number?", " number") assertCommandOutput("setlocal number?", " number")
assertCommandOutput("setlocal relativenumber?", "norelativenumber") assertCommandOutput("setlocal relativenumber?", "norelativenumber")
fixture.editor.settings.lineNumerationType = LineNumerationType.RELATIVE fixture.editor.settings.lineNumerationType = LineNumerationType.RELATIVE
assertCommandOutput("setlocal number?", "nonumber") assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("setlocal relativenumber?", " relativenumber") assertCommandOutput("setlocal relativenumber?", " relativenumber")
}
} }
@Test @Test
@ -234,8 +245,10 @@ class LineNumberOptionsMapperTest : VimTestCase() {
fun `test setting IDE value is treated like setlocal`() { fun `test setting IDE value is treated like setlocal`() {
// If we use `:set`, it updates the local and per-window global values. If we set the value from the IDE, it only // If we use `:set`, it updates the local and per-window global values. If we set the value from the IDE, it only
// affects the local value // affects the local value
fixture.editor.settings.isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID fixture.editor.settings.isLineNumbersShown = true
fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID
}
assertCommandOutput("setlocal number?", " number") assertCommandOutput("setlocal number?", " number")
assertCommandOutput("set number?", " number") assertCommandOutput("set number?", " number")
@ -283,115 +296,129 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Test @Test
fun `test setting global whitespace IDE value will update effective Vim value set during plugin startup`() { fun `test setting global whitespace IDE value will update effective Vim value set during plugin startup`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default // Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
injector.optionGroup.resetAllOptionsForTesting() EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
injector.optionGroup.resetAllOptionsForTesting()
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()
// This is the same value as the global IDE setting. That's ok. We just want to explicitly set the Vim option // This is the same value as the global IDE setting. That's ok. We just want to explicitly set the Vim option
enterCommand("set number") enterCommand("set number")
} finally { } finally {
injector.optionGroup.endInitVimRc() injector.optionGroup.endInitVimRc()
}
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("setglobal number?", "nonumber")
} }
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("setglobal number?", "nonumber")
} }
@Test @Test
fun `test setting global numeration type IDE value will update effective Vim value set during plugin startup`() { fun `test setting global numeration type IDE value will update effective Vim value set during plugin startup`() {
// Default value is ABSOLUTE. Update the global value to something different, but make sure the Vim options are default // Default value is ABSOLUTE. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE ApplicationManager.getApplication().invokeAndWait {
injector.optionGroup.resetAllOptionsForTesting() EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting()
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()
enterCommand("set relativenumber") enterCommand("set relativenumber")
} finally { } finally {
injector.optionGroup.endInitVimRc() injector.optionGroup.endInitVimRc()
}
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
assertCommandOutput("set relativenumber?", "norelativenumber")
assertCommandOutput("setglobal relativenumber?", "norelativenumber")
} }
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
assertCommandOutput("set relativenumber?", "norelativenumber")
assertCommandOutput("setglobal relativenumber?", "norelativenumber")
} }
@Test @Test
fun `test reset 'number' to default copies current global intellij setting`() { fun `test reset 'number' to default copies current global intellij setting`() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
fixture.editor.settings.isLineNumbersShown = false EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
assertCommandOutput("set number?", "nonumber") fixture.editor.settings.isLineNumbersShown = false
assertCommandOutput("set number?", "nonumber")
enterCommand("set number&") enterCommand("set number&")
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown) assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown)
assertEquals(LineNumerationType.ABSOLUTE, EditorSettingsExternalizable.getInstance().lineNumeration) assertEquals(LineNumerationType.ABSOLUTE, EditorSettingsExternalizable.getInstance().lineNumeration)
// Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value // Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
}
} }
@Test @Test
fun `test reset 'relativenumber' to default copies current global intellij setting`() { fun `test reset 'relativenumber' to default copies current global intellij setting`() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting() // So changing the global values does not modify IdeaVim's values EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting() // So changing the global values does not modify IdeaVim's values
// Value becomes External(true) because the user is explicitly setting it // Value becomes External(true) because the user is explicitly setting it
fixture.editor.settings.isLineNumbersShown = false fixture.editor.settings.isLineNumbersShown = false
assertCommandOutput("set relativenumber?", "norelativenumber") assertCommandOutput("set relativenumber?", "norelativenumber")
enterCommand("set relativenumber&") enterCommand("set relativenumber&")
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown) assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown)
assertEquals(LineNumerationType.RELATIVE, EditorSettingsExternalizable.getInstance().lineNumeration) assertEquals(LineNumerationType.RELATIVE, EditorSettingsExternalizable.getInstance().lineNumeration)
// Changing the global value should not update local value, because the user has explicitly changed it // Changing the global value should not update local value, because the user has explicitly changed it
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
}
}
} }
@Test @Test
fun `test local reset 'number' to default copies current global intellij setting`() { fun `test local reset 'number' to default copies current global intellij setting`() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
fixture.editor.settings.isLineNumbersShown = false EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
assertCommandOutput("set number?", "nonumber") fixture.editor.settings.isLineNumbersShown = false
assertCommandOutput("set number?", "nonumber")
enterCommand("setlocal number&") enterCommand("setlocal number&")
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown) assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown)
assertEquals(LineNumerationType.ABSOLUTE, EditorSettingsExternalizable.getInstance().lineNumeration) assertEquals(LineNumerationType.ABSOLUTE, EditorSettingsExternalizable.getInstance().lineNumeration)
// Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value // Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
}
} }
@Test @Test
fun `test reset local 'relativenumber' to default copies current global intellij setting`() { fun `test reset local 'relativenumber' to default copies current global intellij setting`() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
injector.optionGroup.resetAllOptionsForTesting() // So changing the global values does not modify IdeaVim's values EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting() // So changing the global values does not modify IdeaVim's values
// Value becomes External(true) because the user is explicitly setting it // Value becomes External(true) because the user is explicitly setting it
fixture.editor.settings.isLineNumbersShown = false fixture.editor.settings.isLineNumbersShown = false
assertCommandOutput("set relativenumber?", "norelativenumber") assertCommandOutput("set relativenumber?", "norelativenumber")
enterCommand("setlocal relativenumber&") enterCommand("setlocal relativenumber&")
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown) assertTrue(EditorSettingsExternalizable.getInstance().isLineNumbersShown)
assertEquals(LineNumerationType.RELATIVE, EditorSettingsExternalizable.getInstance().lineNumeration) assertEquals(LineNumerationType.RELATIVE, EditorSettingsExternalizable.getInstance().lineNumeration)
// Changing the global value should not update local value, because the user has explicitly changed it // Changing the global value should not update local value, because the user has explicitly changed it
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown) assertTrue(fixture.editor.settings.isLineNumbersShown)
}
} }
@Test @Test
@ -405,8 +432,10 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set number?", "nonumber") assertCommandOutput("set number?", "nonumber")
// Changing the global setting should update the new editor // Changing the global setting should update the new editor
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
}
assertCommandOutput("set number?", " number") assertCommandOutput("set number?", " number")
} }
@ -414,16 +443,18 @@ class LineNumberOptionsMapperTest : VimTestCase() {
fun `test open new window without setting 'relativenumber' copies value as not-explicitly set`() { fun `test open new window without setting 'relativenumber' copies value as not-explicitly set`() {
// New window will clone local and global local-to-window options, then apply global to local. This tests that our // New window will clone local and global local-to-window options, then apply global to local. This tests that our
// handling of per-window "global" values is correct. // handling of per-window "global" values is correct.
assertCommandOutput("set relativenumber?", "norelativenumber") ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set relativenumber?", "norelativenumber")
switchToNewFile("bbb.txt", "lorem ipsum") switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set relativenumber?", "norelativenumber") assertCommandOutput("set relativenumber?", "norelativenumber")
// Changing the global setting should update the new editor // Changing the global setting should update the new editor
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
assertCommandOutput("set relativenumber?", " relativenumber") assertCommandOutput("set relativenumber?", " relativenumber")
}
} }
@Test @Test
@ -517,44 +548,48 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Test @Test
fun `test setting global whitespace IDE value will update effective Vim value in new window initialised during startup`() { fun `test setting global whitespace IDE value will update effective Vim value in new window initialised during startup`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default // Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true ApplicationManager.getApplication().invokeAndWait {
injector.optionGroup.resetAllOptionsForTesting() EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
injector.optionGroup.resetAllOptionsForTesting()
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()
enterCommand("set number") enterCommand("set number")
} finally { } finally {
injector.optionGroup.endInitVimRc() injector.optionGroup.endInitVimRc()
}
switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set number?", " number")
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("setglobal number?", "nonumber")
} }
switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set number?", " number")
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("setglobal number?", "nonumber")
} }
@Test @Test
fun `test setting global numeration type IDE value will update effective Vim value in new window initialised during startup`() { fun `test setting global numeration type IDE value will update effective Vim value in new window initialised during startup`() {
// Default value is ABSOLUTE. Update the global value to something different, but make sure the Vim options are default // Default value is ABSOLUTE. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE ApplicationManager.getApplication().invokeAndWait {
injector.optionGroup.resetAllOptionsForTesting() EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting()
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()
enterCommand("set relativenumber") enterCommand("set relativenumber")
} finally { } finally {
injector.optionGroup.endInitVimRc() injector.optionGroup.endInitVimRc()
}
switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set relativenumber?", " relativenumber")
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
assertCommandOutput("set relativenumber?", "norelativenumber")
assertCommandOutput("setglobal relativenumber?", "norelativenumber")
} }
switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set relativenumber?", " relativenumber")
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
assertCommandOutput("set relativenumber?", "norelativenumber")
assertCommandOutput("setglobal relativenumber?", "norelativenumber")
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.IjOptions import com.maddyhome.idea.vim.group.IjOptions
@ -31,7 +32,9 @@ class ListOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -167,7 +170,11 @@ class ListOptionMapperTest : VimTestCase() {
fun `test setting global IDE value will update effective Vim value set during plugin startup`() { fun `test setting global IDE value will update effective Vim value set during plugin startup`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default // Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isWhitespacesShown = true EditorSettingsExternalizable.getInstance().isWhitespacesShown = true
injector.optionGroup.resetAllOptionsForTesting() ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()
@ -288,7 +295,11 @@ class ListOptionMapperTest : VimTestCase() {
fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() { fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default // Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isWhitespacesShown = true EditorSettingsExternalizable.getInstance().isWhitespacesShown = true
injector.optionGroup.resetAllOptionsForTesting() ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try { try {
injector.optionGroup.startInitVimRc() injector.optionGroup.startInitVimRc()

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -39,7 +40,9 @@ class ScrollJumpOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -38,7 +39,9 @@ class ScrollOffOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -160,10 +163,13 @@ class ScrollOffOptionMapperTest : VimTestCase() {
fun `test setting global IDE value will update IdeaVim value`() { fun `test setting global IDE value will update IdeaVim value`() {
enterCommand("set scrolloff=10") enterCommand("set scrolloff=10")
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 20 ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set scrolloff?", " scrolloff=20") EditorSettingsExternalizable.getInstance().verticalScrollOffset = 20
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertCommandOutput("setglobal scrolloff?", " scrolloff=20") assertCommandOutput("set scrolloff?", " scrolloff=20")
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertCommandOutput("setglobal scrolloff?", " scrolloff=20")
}
} }
@Test @Test
@ -199,16 +205,18 @@ class ScrollOffOptionMapperTest : VimTestCase() {
assertCommandOutput("set scrolloff?", " scrolloff=20") assertCommandOutput("set scrolloff?", " scrolloff=20")
// Changing the global IntelliJ setting syncs with the global Vim value // Changing the global IntelliJ setting syncs with the global Vim value
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 10 ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set scrolloff?", " scrolloff=10") EditorSettingsExternalizable.getInstance().verticalScrollOffset = 10
assertCommandOutput("set scrolloff?", " scrolloff=10")
// We don't support externally changing the local editor setting // We don't support externally changing the local editor setting
enterCommand("setlocal scrolloff=30") enterCommand("setlocal scrolloff=30")
assertCommandOutput("set scrolloff?", " scrolloff=30") assertCommandOutput("set scrolloff?", " scrolloff=30")
assertCommandOutput("setlocal scrolloff?", " scrolloff=30") assertCommandOutput("setlocal scrolloff?", " scrolloff=30")
assertCommandOutput("setglobal scrolloff?", " scrolloff=10") assertCommandOutput("setglobal scrolloff?", " scrolloff=10")
assertEquals(10, EditorSettingsExternalizable.getInstance().verticalScrollOffset) assertEquals(10, EditorSettingsExternalizable.getInstance().verticalScrollOffset)
assertEquals(0, fixture.editor.settings.verticalScrollOffset) assertEquals(0, fixture.editor.settings.verticalScrollOffset)
}
} }
@Test @Test
@ -270,29 +278,31 @@ class ScrollOffOptionMapperTest : VimTestCase() {
@Test @Test
fun `test reset 'scrolloff' to default value resets global value to intellij global value for all editors`() { fun `test reset 'scrolloff' to default value resets global value to intellij global value for all editors`() {
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 20 ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 20
val firstEditor = fixture.editor val firstEditor = fixture.editor
switchToNewFile("bbb.txt", "lorem ipsum") switchToNewFile("bbb.txt", "lorem ipsum")
enterCommand("set scrolloff=10") enterCommand("set scrolloff=10")
assertCommandOutput("set scrolloff?", " scrolloff=10") assertCommandOutput("set scrolloff?", " scrolloff=10")
assertCommandOutput("setglobal scrolloff?", " scrolloff=10") assertCommandOutput("setglobal scrolloff?", " scrolloff=10")
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1") assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertEquals(10, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?` assertEquals(10, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?`
enterCommand("set scrolloff&") enterCommand("set scrolloff&")
assertCommandOutput("set scrolloff?", " scrolloff=20") assertCommandOutput("set scrolloff?", " scrolloff=20")
assertCommandOutput("setglobal scrolloff?", " scrolloff=20") assertCommandOutput("setglobal scrolloff?", " scrolloff=20")
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1") assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertEquals(20, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?` assertEquals(20, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?`
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 15 EditorSettingsExternalizable.getInstance().verticalScrollOffset = 15
assertCommandOutput("set scrolloff?", " scrolloff=15") assertCommandOutput("set scrolloff?", " scrolloff=15")
assertCommandOutput("setglobal scrolloff?", " scrolloff=15") assertCommandOutput("setglobal scrolloff?", " scrolloff=15")
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1") assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertEquals(15, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?` assertEquals(15, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?`
}
} }
@Test @Test

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -38,7 +39,9 @@ class SideScrollOffOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -39,7 +40,9 @@ class SideScrollOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ComponentManagerEx import com.intellij.openapi.components.ComponentManagerEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.FileEditorManager
@ -50,7 +51,9 @@ class WrapOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) { private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor // This replaces fixture.editor
fixture.openFileInEditor(fixture.createFile(filename, content)) ApplicationManager.getApplication().invokeAndWait {
fixture.openFileInEditor(fixture.createFile(filename, content))
}
// But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry // But our selection changed callback doesn't get called immediately, and that callback will deactivate the ex entry
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time // panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -72,38 +75,46 @@ class WrapOptionMapperTest : VimTestCase() {
@Test @Test
fun `test 'wrap' option reports current global intellij setting if not explicitly set`() { fun `test 'wrap' option reports current global intellij setting if not explicitly set`() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set wrap?", "nowrap") EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap")
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("set wrap?", " wrap") assertCommandOutput("set wrap?", " wrap")
}
} }
@Test @Test
fun `test local 'wrap' option reports current global intellij setting if not explicitly set`() { fun `test local 'wrap' option reports current global intellij setting if not explicitly set`() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal wrap?", "nowrap") EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap")
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("setlocal wrap?", " wrap") assertCommandOutput("setlocal wrap?", " wrap")
}
} }
@Test @Test
fun `test 'wrap' option reports local intellij setting if set via IDE`() { fun `test 'wrap' option reports local intellij setting if set via IDE`() {
fixture.editor.settings.isUseSoftWraps = true ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set wrap?", " wrap") fixture.editor.settings.isUseSoftWraps = true
assertCommandOutput("set wrap?", " wrap")
fixture.editor.settings.isUseSoftWraps = false fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap") assertCommandOutput("set wrap?", "nowrap")
}
} }
@Test @Test
fun `test local 'wrap' option reports local intellij setting if set via IDE`() { fun `test local 'wrap' option reports local intellij setting if set via IDE`() {
fixture.editor.settings.isUseSoftWraps = true ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal wrap?", " wrap") fixture.editor.settings.isUseSoftWraps = true
assertCommandOutput("setlocal wrap?", " wrap")
fixture.editor.settings.isUseSoftWraps = false fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap") assertCommandOutput("setlocal wrap?", "nowrap")
}
} }
@Test @Test
@ -132,13 +143,15 @@ class WrapOptionMapperTest : VimTestCase() {
@Test @Test
fun `test setglobal 'wrap' option affects IdeaVim global value only`() { fun `test setglobal 'wrap' option affects IdeaVim global value only`() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setglobal wrap?", " wrap") // Default for IdeaVim option is true EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("setglobal wrap?", " wrap") // Default for IdeaVim option is true
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
enterCommand("setglobal nowrap") enterCommand("setglobal nowrap")
assertCommandOutput("setglobal wrap?", "nowrap") assertCommandOutput("setglobal wrap?", "nowrap")
assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps) assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps)
}
} }
@Test @Test
@ -152,10 +165,12 @@ class WrapOptionMapperTest : VimTestCase() {
fun `test setting local IDE value is treated like setlocal`() { fun `test setting local IDE value is treated like setlocal`() {
// If we use `:set`, it updates the local and per-window global values. If we set the value from the IDE, it only // If we use `:set`, it updates the local and per-window global values. If we set the value from the IDE, it only
// affects the local value // affects the local value
fixture.editor.settings.isUseSoftWraps = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal wrap?", "nowrap") fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap") assertCommandOutput("setlocal wrap?", "nowrap")
assertCommandOutput("setglobal wrap?", " wrap") assertCommandOutput("set wrap?", "nowrap")
assertCommandOutput("setglobal wrap?", " wrap")
}
} }
@Test @Test
@ -175,19 +190,21 @@ class WrapOptionMapperTest : VimTestCase() {
@Test @Test
fun `test setting global IDE value will update effective Vim value set during plugin startup`() { fun `test setting global IDE value will update effective Vim value set during plugin startup`() {
try { ApplicationManager.getApplication().invokeAndWait {
injector.optionGroup.startInitVimRc() try {
enterCommand("set nowrap") injector.optionGroup.startInitVimRc()
} finally { enterCommand("set nowrap")
injector.optionGroup.endInitVimRc() } finally {
} injector.optionGroup.endInitVimRc()
}
// Default is true, so reset it to false, then set back to true // Default is true, so reset it to false, then set back to true
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("setlocal wrap?", " wrap") assertCommandOutput("setlocal wrap?", " wrap")
assertCommandOutput("set wrap?", " wrap") assertCommandOutput("set wrap?", " wrap")
assertCommandOutput("setglobal wrap?", " wrap") assertCommandOutput("setglobal wrap?", " wrap")
}
} }
@Test @Test
@ -204,46 +221,52 @@ class WrapOptionMapperTest : VimTestCase() {
@Test @Test
fun `test reset 'wrap' to default copies current global intellij setting`() { fun `test reset 'wrap' to default copies current global intellij setting`() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isUseSoftWraps = false EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("set wrap?", "nowrap") fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap")
enterCommand("set wrap&") enterCommand("set wrap&")
assertTrue(fixture.editor.settings.isUseSoftWraps) assertTrue(fixture.editor.settings.isUseSoftWraps)
assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps) assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps)
// Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value // Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertTrue(fixture.editor.settings.isUseSoftWraps) assertTrue(fixture.editor.settings.isUseSoftWraps)
}
} }
@Test @Test
fun `test reset local 'wrap' to default copies current global intellij setting`() { fun `test reset local 'wrap' to default copies current global intellij setting`() {
fixture.editor.settings.isUseSoftWraps = false ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("setlocal wrap?", "nowrap") fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap")
enterCommand("setlocal wrap&") enterCommand("setlocal wrap&")
assertTrue(fixture.editor.settings.isUseSoftWraps) assertTrue(fixture.editor.settings.isUseSoftWraps)
assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps) assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps)
// Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value // Verify that IntelliJ doesn't allow us to "unset" a local editor setting - it's a copy of the default value
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertTrue(fixture.editor.settings.isUseSoftWraps) assertTrue(fixture.editor.settings.isUseSoftWraps)
}
} }
@Test @Test
fun `test open new window without setting the option copies value as not-explicitly set`() { fun `test open new window without setting the option copies value as not-explicitly set`() {
// New window will clone local and global local-to-window options, then apply global to local. This tests that our // New window will clone local and global local-to-window options, then apply global to local. This tests that our
// handling of per-window "global" values is correct. // handling of per-window "global" values is correct.
assertCommandOutput("set wrap?", " wrap") ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set wrap?", " wrap")
switchToNewFile("bbb.txt", "lorem ipsum") switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set wrap?", " wrap") assertCommandOutput("set wrap?", " wrap")
// Changing the global setting should update the new editor // Changing the global setting should update the new editor
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap") assertCommandOutput("set wrap?", "nowrap")
}
} }
@Test @Test
@ -292,20 +315,22 @@ class WrapOptionMapperTest : VimTestCase() {
@Test @Test
fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() { fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() {
try { ApplicationManager.getApplication().invokeAndWait {
injector.optionGroup.startInitVimRc() try {
enterCommand("set nowrap") injector.optionGroup.startInitVimRc()
} finally { enterCommand("set nowrap")
injector.optionGroup.endInitVimRc() } finally {
injector.optionGroup.endInitVimRc()
}
switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set wrap?", "nowrap")
// Changing the global setting should update the editor, because it was initially set during plugin startup
// Default is true, so reset before changing again
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("set wrap?", " wrap")
} }
switchToNewFile("bbb.txt", "lorem ipsum")
assertCommandOutput("set wrap?", "nowrap")
// Changing the global setting should update the editor, because it was initially set during plugin startup
// Default is true, so reset before changing again
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("set wrap?", " wrap")
} }
} }

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.regex package org.jetbrains.plugins.ideavim.regex
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.VisualPosition import com.intellij.openapi.editor.VisualPosition
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
@ -20,8 +21,12 @@ import kotlin.test.assertEquals
class VimRegexEngineTest : VimTestCase() { class VimRegexEngineTest : VimTestCase() {
private fun findAll(pattern: String): List<TextRange> { private fun findAll(pattern: String): List<TextRange> {
val regex = VimRegex(pattern) var result: List<TextRange>? = null
return regex.findAll(fixture.editor.vim).map { it.range } ApplicationManager.getApplication().runReadAction {
val regex = VimRegex(pattern)
result = regex.findAll(fixture.editor.vim).map { it.range }
}
return result!!
} }
@Test @Test
@ -79,11 +84,13 @@ class VimRegexEngineTest : VimTestCase() {
configureByText("Lor${c}em ${c}Ipsum") configureByText("Lor${c}em ${c}Ipsum")
val editor = fixture.editor.vim val editor = fixture.editor.vim
val mark = VimMark.create('m', 0, 0, editor.getPath(), editor.extractProtocol())!! val mark = VimMark.create('m', 0, 0, editor.getPath(), editor.extractProtocol())!!
val secondCaret = editor.carets().maxByOrNull { it.offset }!! ApplicationManager.getApplication().invokeAndWait {
secondCaret.markStorage.setMark(mark) val secondCaret = editor.carets().maxByOrNull { it.offset }!!
secondCaret.markStorage.setMark(mark)
val result = findAll("\\%>'m\\%#.") val result = findAll("\\%>'m\\%#.")
assertEquals(result, listOf(TextRange(6, 7))) assertEquals(result, listOf(TextRange(6, 7)))
}
} }
@Test @Test
@ -141,15 +148,17 @@ class VimRegexEngineTest : VimTestCase() {
val caretModel = fixture.editor.caretModel val caretModel = fixture.editor.caretModel
typeText("v") // a workaround to trigger visual mode typeText("v") // a workaround to trigger visual mode
caretModel.addCaret(VisualPosition(0, 2)) ApplicationManager.getApplication().invokeAndWait {
val caret = caretModel.getCaretAt(VisualPosition(0, 2))!! caretModel.addCaret(VisualPosition(0, 2))
caret.setSelection(0, 5) val caret = caretModel.getCaretAt(VisualPosition(0, 2))!!
caretModel.addCaret(VisualPosition(0, 0)) caret.setSelection(0, 5)
caretModel.addCaret(VisualPosition(0, 1)) caretModel.addCaret(VisualPosition(0, 0))
caretModel.addCaret(VisualPosition(0, 3)) caretModel.addCaret(VisualPosition(0, 1))
caretModel.addCaret(VisualPosition(0, 3))
val result = findAll("\\%V.\\{-}\\%#.") val result = findAll("\\%V.\\{-}\\%#.")
assertEquals(result, listOf(TextRange(0, 3))) assertEquals(result, listOf(TextRange(0, 3)))
}
} }
} }

View File

@ -47,7 +47,6 @@ import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl
import com.intellij.testFramework.junit5.RunInEdt
import com.intellij.util.ui.EmptyClipboardOwner import com.intellij.util.ui.EmptyClipboardOwner
import com.maddyhome.idea.vim.KeyHandler import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
@ -78,7 +77,6 @@ import com.maddyhome.idea.vim.key.MappingOwner
import com.maddyhome.idea.vim.key.ToKeysMappingInfo import com.maddyhome.idea.vim.key.ToKeysMappingInfo
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
import com.maddyhome.idea.vim.listener.VimListenerManager import com.maddyhome.idea.vim.listener.VimListenerManager
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.globalIjOptions import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.ijOptions import com.maddyhome.idea.vim.newapi.ijOptions
import com.maddyhome.idea.vim.newapi.vim import com.maddyhome.idea.vim.newapi.vim
@ -113,31 +111,8 @@ import kotlin.test.assertTrue
* To plugin writers: this class is internal, thus not allowed to be used by third-party plugins. * To plugin writers: this class is internal, thus not allowed to be used by third-party plugins.
* This is done as we have no mechanism to guarantee compatibility as we update this test case. * This is done as we have no mechanism to guarantee compatibility as we update this test case.
* Feel free to copy this class into your plugin, or copy just needed functions. * Feel free to copy this class into your plugin, or copy just needed functions.
*
* Deprecated: Use [IdeaVimTestCase]
* Tests with [VimTestCase] are always started on the EDT with the write action. This is not only incorrect but also
* prevents an implementation of VIM-3376.
*
* If your test fails because of:
* Missing EDT: Wrap with `ApplicationManager.getInstance().invokeAndWait { }`
* Missing Write Action: Wrap with `ApplicationManager.getInstance().runWriteAction { }`
* Missing Read Action: Wrap with `ApplicationManager.getInstance().runReadAction { }`
*
* This wrapping may be needed right in the test if there is a platform call in the test itself.
* E.g. `fixture.editor.foldingModel.runBatchFoldingOperation`.
*
* However, there is a chance that the platform call happens deep in IdeaVim code. IdeaVim historically uses
* very broad EDT and write action scopes. This means we wrap with the write action almost at the top of the
* call stack. This is incorrect, the write action should be taken only in the place where it's necessary.
* So, try to properly introduce a write/read action wrapping in the IdeaVim code. If it's too complicated,
* wrap with write/read action the call in the test and mark it that the action wrapping should be done deeper in the code.
*/ */
@RunInEdt(writeIntent = true)
@ApiStatus.Internal @ApiStatus.Internal
@Deprecated(
"Use IdeaVimTestCase instead",
replaceWith = ReplaceWith("IdeaVimTestCase", "org.jetbrains.plugins.ideavim.IdeaVimTestCase")
)
abstract class VimTestCase : IdeaVimTestCase() { abstract class VimTestCase : IdeaVimTestCase() {
object Checks { object Checks {
var caretShape: Boolean = true var caretShape: Boolean = true
@ -245,7 +220,9 @@ abstract class IdeaVimTestCase {
private fun setDefaultIntelliJSettings(editor: Editor) { private fun setDefaultIntelliJSettings(editor: Editor) {
// These settings don't have a global setting... // These settings don't have a global setting...
editor.settings.isCaretRowShown = IjOptions.cursorline.defaultValue.asBoolean() ApplicationManager.getApplication().invokeAndWait {
editor.settings.isCaretRowShown = IjOptions.cursorline.defaultValue.asBoolean()
}
} }
protected open fun createFixture(factory: IdeaTestFixtureFactory): CodeInsightTestFixture { protected open fun createFixture(factory: IdeaTestFixtureFactory): CodeInsightTestFixture {
@ -324,13 +301,17 @@ abstract class IdeaVimTestCase {
protected fun setEditorVisibleSize(width: Int, height: Int) { protected fun setEditorVisibleSize(width: Int, height: Int) {
val w = (width * EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt() val w = (width * EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
val h = height * fixture.editor.lineHeight val h = height * fixture.editor.lineHeight
EditorTestUtil.setEditorVisibleSizeInPixels(fixture.editor, w, h) ApplicationManager.getApplication().invokeAndWait {
EditorTestUtil.setEditorVisibleSizeInPixels(fixture.editor, w, h)
}
} }
protected fun setEditorVirtualSpace() { protected fun setEditorVirtualSpace() {
// Enable virtual space at the bottom of the file and force a layout to pick up the changes ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isAdditionalPageAtBottom = true // Enable virtual space at the bottom of the file and force a layout to pick up the changes
(fixture.editor as EditorEx).scrollPane.viewport.doLayout() fixture.editor.settings.isAdditionalPageAtBottom = true
(fixture.editor as EditorEx).scrollPane.viewport.doLayout()
}
} }
protected fun configureByText(content: String) = configureByText(PlainTextFileType.INSTANCE, content) protected fun configureByText(content: String) = configureByText(PlainTextFileType.INSTANCE, content)
@ -340,17 +321,21 @@ abstract class IdeaVimTestCase {
protected fun configureAndGuard(content: String) { protected fun configureAndGuard(content: String) {
val ranges = extractBrackets(content) val ranges = extractBrackets(content)
for ((start, end) in ranges) { ApplicationManager.getApplication().runReadAction {
fixture.editor.document.createGuardedBlock(start, end) for ((start, end) in ranges) {
fixture.editor.document.createGuardedBlock(start, end)
}
} }
} }
protected fun configureAndFold(content: String, @Suppress("SameParameterValue") placeholder: String) { protected fun configureAndFold(content: String, @Suppress("SameParameterValue") placeholder: String) {
val ranges = extractBrackets(content) val ranges = extractBrackets(content)
fixture.editor.foldingModel.runBatchFoldingOperation { ApplicationManager.getApplication().invokeAndWait {
for ((start, end) in ranges) { fixture.editor.foldingModel.runBatchFoldingOperation {
val foldRegion = fixture.editor.foldingModel.addFoldRegion(start, end, placeholder) for ((start, end) in ranges) {
foldRegion?.isExpanded = false val foldRegion = fixture.editor.foldingModel.addFoldRegion(start, end, placeholder)
foldRegion?.isExpanded = false
}
} }
} }
} }
@ -462,12 +447,14 @@ abstract class IdeaVimTestCase {
assertTopLogicalLine(scrollToLogicalLine) assertTopLogicalLine(scrollToLogicalLine)
assertPosition(caretLogicalLine, caretLogicalColumn) assertPosition(caretLogicalLine, caretLogicalColumn)
// Belt and braces. Let's make sure that the caret is fully onscreen ApplicationManager.getApplication().invokeAndWait {
val bottomLogicalLine = fixture.editor.vim.visualLineToBufferLine( // Belt and braces. Let's make sure that the caret is fully onscreen
EditorHelper.getVisualLineAtBottomOfScreen(fixture.editor), val bottomLogicalLine = fixture.editor.vim.visualLineToBufferLine(
) EditorHelper.getVisualLineAtBottomOfScreen(fixture.editor),
assertTrue(bottomLogicalLine >= caretLogicalLine) )
assertTrue(caretLogicalLine >= scrollToLogicalLine) assertTrue(bottomLogicalLine >= caretLogicalLine)
assertTrue(caretLogicalLine >= scrollToLogicalLine)
}
} }
protected fun typeText(vararg keys: String) = typeText(keys.flatMap { injector.parser.parseKeys(it) }) protected fun typeText(vararg keys: String) = typeText(keys.flatMap { injector.parser.parseKeys(it) })
@ -651,36 +638,46 @@ abstract class IdeaVimTestCase {
// Use logical rather than visual lines, so we can correctly test handling of collapsed folds and soft wraps // Use logical rather than visual lines, so we can correctly test handling of collapsed folds and soft wraps
fun assertVisibleArea(topLogicalLine: Int, bottomLogicalLine: Int) { fun assertVisibleArea(topLogicalLine: Int, bottomLogicalLine: Int) {
assertTopLogicalLine(topLogicalLine) ApplicationManager.getApplication().invokeAndWait {
assertBottomLogicalLine(bottomLogicalLine) ApplicationManager.getApplication().runReadAction {
assertTopLogicalLine(topLogicalLine)
assertBottomLogicalLine(bottomLogicalLine)
}
}
} }
fun assertTopLogicalLine(topLogicalLine: Int) { fun assertTopLogicalLine(topLogicalLine: Int) {
val actualVisualTop = EditorHelper.getVisualLineAtTopOfScreen(fixture.editor) ApplicationManager.getApplication().invokeAndWait {
val actualLogicalTop = fixture.editor.vim.visualLineToBufferLine(actualVisualTop) val actualVisualTop = EditorHelper.getVisualLineAtTopOfScreen(fixture.editor)
val actualLogicalTop = fixture.editor.vim.visualLineToBufferLine(actualVisualTop)
assertEquals(topLogicalLine, actualLogicalTop, "Top logical lines don't match") assertEquals(topLogicalLine, actualLogicalTop, "Top logical lines don't match")
}
} }
fun assertBottomLogicalLine(bottomLogicalLine: Int) { fun assertBottomLogicalLine(bottomLogicalLine: Int) {
val actualVisualBottom = EditorHelper.getVisualLineAtBottomOfScreen(fixture.editor) ApplicationManager.getApplication().invokeAndWait {
val actualLogicalBottom = fixture.editor.vim.visualLineToBufferLine(actualVisualBottom) val actualVisualBottom = EditorHelper.getVisualLineAtBottomOfScreen(fixture.editor)
val actualLogicalBottom = fixture.editor.vim.visualLineToBufferLine(actualVisualBottom)
assertEquals(bottomLogicalLine, actualLogicalBottom, "Bottom logical lines don't match") assertEquals(bottomLogicalLine, actualLogicalBottom, "Bottom logical lines don't match")
}
} }
fun assertVisibleLineBounds(logicalLine: Int, leftLogicalColumn: Int, rightLogicalColumn: Int) { fun assertVisibleLineBounds(logicalLine: Int, leftLogicalColumn: Int, rightLogicalColumn: Int) {
val visualLine = IjVimEditor(fixture.editor).bufferLineToVisualLine(logicalLine) ApplicationManager.getApplication().invokeAndWait {
val actualLeftVisualColumn = EditorHelper.getVisualColumnAtLeftOfDisplay(fixture.editor, visualLine) val visualLine = fixture.editor.vim.bufferLineToVisualLine(logicalLine)
val actualLeftLogicalColumn = val actualLeftVisualColumn = EditorHelper.getVisualColumnAtLeftOfDisplay(fixture.editor, visualLine)
fixture.editor.visualToLogicalPosition(VisualPosition(visualLine, actualLeftVisualColumn)).column val actualLeftLogicalColumn =
val actualRightVisualColumn = EditorHelper.getVisualColumnAtRightOfDisplay(fixture.editor, visualLine) fixture.editor.visualToLogicalPosition(VisualPosition(visualLine, actualLeftVisualColumn)).column
val actualRightLogicalColumn = val actualRightVisualColumn = EditorHelper.getVisualColumnAtRightOfDisplay(fixture.editor, visualLine)
fixture.editor.visualToLogicalPosition(VisualPosition(visualLine, actualRightVisualColumn)).column val actualRightLogicalColumn =
fixture.editor.visualToLogicalPosition(VisualPosition(visualLine, actualRightVisualColumn)).column
val expected = ScreenBounds(leftLogicalColumn, rightLogicalColumn) val expected = ScreenBounds(leftLogicalColumn, rightLogicalColumn)
val actual = ScreenBounds(actualLeftLogicalColumn, actualRightLogicalColumn) val actual = ScreenBounds(actualLeftLogicalColumn, actualRightLogicalColumn)
assertEquals(expected, actual) assertEquals(expected, actual)
}
} }
fun assertLineCount(expected: Int) { fun assertLineCount(expected: Int) {
@ -953,8 +950,12 @@ abstract class IdeaVimTestCase {
relatesToPrecedingText: Boolean, relatesToPrecedingText: Boolean,
@Suppress("SameParameterValue") widthInColumns: Int, @Suppress("SameParameterValue") widthInColumns: Int,
): Inlay<*> { ): Inlay<*> {
val widthInPixels = (EditorHelper.getPlainSpaceWidthFloat(fixture.editor) * widthInColumns).roundToInt() var inlay: Inlay<*>? = null
return EditorTestUtil.addInlay(fixture.editor, offset, relatesToPrecedingText, widthInPixels) ApplicationManager.getApplication().invokeAndWait {
val widthInPixels = (EditorHelper.getPlainSpaceWidthFloat(fixture.editor) * widthInColumns).roundToInt()
inlay = EditorTestUtil.addInlay(fixture.editor, offset, relatesToPrecedingText, widthInPixels)
}
return inlay!!
} }
// As for inline inlays, height is specified as a multiplier of line height, as we can't guarantee the same line // As for inline inlays, height is specified as a multiplier of line height, as we can't guarantee the same line
@ -969,7 +970,11 @@ abstract class IdeaVimTestCase {
val widthInColumns = 10 // Arbitrary width. We don't care. val widthInColumns = 10 // Arbitrary width. We don't care.
val widthInPixels = (EditorHelper.getPlainSpaceWidthFloat(fixture.editor) * widthInColumns).roundToInt() val widthInPixels = (EditorHelper.getPlainSpaceWidthFloat(fixture.editor) * widthInColumns).roundToInt()
val heightInPixels = fixture.editor.lineHeight * heightInRows val heightInPixels = fixture.editor.lineHeight * heightInRows
return EditorTestUtil.addBlockInlay(fixture.editor, offset, false, showAbove, widthInPixels, heightInPixels) var inlay: Inlay<*>? = null
ApplicationManager.getApplication().invokeAndWait {
inlay = EditorTestUtil.addBlockInlay(fixture.editor, offset, false, showAbove, widthInPixels, heightInPixels)
}
return inlay!!
} }
// Disable or enable checks for the particular test // Disable or enable checks for the particular test

View File

@ -10,6 +10,7 @@ package com.maddyhome.idea.vim.api
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.common.VimCopiedText import com.maddyhome.idea.vim.common.VimCopiedText
import com.maddyhome.idea.vim.helper.RWLockLabel
import java.awt.datatransfer.Transferable import java.awt.datatransfer.Transferable
/** /**
@ -50,6 +51,7 @@ interface VimClipboardManager {
fun dumbCopiedText(text: String): VimCopiedText // TODO this method is NOT preffered, it does not collect transferableData fun dumbCopiedText(text: String): VimCopiedText // TODO this method is NOT preffered, it does not collect transferableData
@RWLockLabel.Readonly
fun getTransferableData(vimEditor: VimEditor, textRange: TextRange): List<Any> fun getTransferableData(vimEditor: VimEditor, textRange: TextRange): List<Any>
fun preprocessText( fun preprocessText(

View File

@ -83,14 +83,16 @@ sealed class Command(
if (Flag.SAVE_VISUAL !in argFlags.flags) { if (Flag.SAVE_VISUAL !in argFlags.flags) {
// Editor.inBlockSelection is not available, because we're not in Visual mode anymore. Check if the primary caret // Editor.inBlockSelection is not available, because we're not in Visual mode anymore. Check if the primary caret
// currently has a selection and if (when we still in Visual) it was a block selection. // currently has a selection and if (when we still in Visual) it was a block selection.
if (editor.primaryCaret().hasSelection() && editor.primaryCaret().lastSelectionInfo.selectionType.isBlock) { injector.application.runReadAction {
editor.removeSecondaryCarets() if (editor.primaryCaret().hasSelection() && editor.primaryCaret().lastSelectionInfo.selectionType.isBlock) {
} editor.removeSecondaryCarets()
editor.nativeCarets().forEach { }
if (it.hasSelection()) { editor.nativeCarets().forEach {
val offset = it.selectionStart if (it.hasSelection()) {
it.removeSelection() val offset = it.selectionStart
it.moveToOffset(offset) it.removeSelection()
it.moveToOffset(offset)
}
} }
} }
} }