1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-31 16:34:06 +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.ex.EditorEx
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.api.VimEditor
import com.maddyhome.idea.vim.api.globalOptions
@ -88,7 +89,9 @@ private fun isBlockCursorOverride() = EditorSettingsExternalizable.getInstance()
private fun Editor.updatePrimaryCaretVisualAttributes() {
if (VimPlugin.isNotEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
if (isIdeaVimDisabledHere) return
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
// NOTE: At the moment, this causes project leak in tests
@ -163,12 +166,14 @@ class CaretVisualAttributesListener : IsReplaceCharListener, ModeChangeListener,
updateCaretsVisual(editor)
}
@RequiresEdt
private fun updateCaretsVisual(editor: VimEditor) {
val ijEditor = (editor as IjVimEditor).editor
ijEditor.updateCaretsVisualAttributes()
ijEditor.updateCaretsVisualPosition()
}
@RequiresEdt
fun updateAllEditorsCaretsVisual() {
injector.editorGroup.getEditors().forEach { 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.LogicalPosition
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
@ -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
* 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) {
// If the target is inside a fold, call the standard moveToOffset to expand and move
if (editor.foldingModel.isOffsetCollapsed(offset) || !editor.hasBlockOrUnderscoreCaret()) {
@ -51,6 +54,7 @@ internal fun Caret.moveToInlayAwareLogicalPosition(pos: LogicalPosition) {
moveToInlayAwareOffset(editor.logicalPositionToOffset(pos))
}
@RequiresEdt
private fun getVisualPositionForTextAtOffset(editor: Editor, offset: Int): VisualPosition {
var logicalPosition = editor.offsetToLogicalPosition(offset)
val e = if (editor is EditorWindow) {
@ -81,15 +85,18 @@ internal fun Editor.amountOfInlaysBeforeVisualPosition(pos: VisualPosition): Int
return this.inlayModel.getInlineElementsInRange(lineStartOffset, offset).size
}
@RequiresEdt
internal fun Editor.updateCaretsVisualPosition() {
// 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
// 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
// right location. Don't open a fold if the caret is inside
injector.application.runReadAction {
this.vimForEachCaret {
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.modeChangeListeners.add(caretVisualAttributesListener)
injector.listenersNotifier.isReplaceCharListeners.add(caretVisualAttributesListener)
ApplicationManager.getApplication().invokeAndWait {
caretVisualAttributesListener.updateAllEditorsCaretsVisual()
}
val insertTimeRecorder = InsertTimeRecorder()
injector.listenersNotifier.modeChangeListeners.add(insertTimeRecorder)
@ -328,9 +330,11 @@ internal object VimListenerManager {
injector.listenersNotifier.notifyEditorCreated(vimEditor)
Disposer.register(perEditorDisposable) {
ApplicationManager.getApplication().invokeLater {
VimPlugin.getEditor().editorDeinit(editor)
}
}
}
fun remove(editor: Editor) {
val editorDisposable = editor.removeUserData(editorListenersDisposableKey)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.change.delete
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.ideavim.VimTestCase
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
typeText("70zl")
assertVisualPosition(0, 75)
ApplicationManager.getApplication().invokeAndWait {
assertVisibleLineBounds(0, 70, 149)
}
typeText("20X")

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.action.change.insert
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.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason
@ -147,11 +148,13 @@ class VisualBlockInsertActionTest : VimTestCase() {
hard by the torrent of a mountain pass.
""".trimIndent(),
) {
ApplicationManager.getApplication().invokeAndWait {
it.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello"))
it.inlayModel.addInlineElement(before.indexOf("l rocks"), HintRenderer("Hello"))
it.inlayModel.addInlineElement(before.indexOf("ere it"), HintRenderer("Hello"))
}
}
}
@TestWithoutNeovim(SkipNeovimReason.VISUAL_BLOCK_MODE)
@Test

View File

@ -11,6 +11,7 @@ package org.jetbrains.plugins.ideavim.action.copy
import com.intellij.notification.ActionCenter
import com.intellij.notification.EventLog
import com.intellij.notification.Notification
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.NotificationService
@ -34,6 +35,7 @@ class IdeaPutNotificationsTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -42,6 +44,7 @@ class IdeaPutNotificationsTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("p"))
val notification = notifications().last()
@ -62,6 +65,7 @@ class IdeaPutNotificationsTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -70,6 +74,7 @@ class IdeaPutNotificationsTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("p"))
val notifications = notifications()
@ -88,6 +93,7 @@ class IdeaPutNotificationsTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -96,6 +102,7 @@ class IdeaPutNotificationsTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("p"))
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.CopyPastePreProcessor
import com.intellij.codeInsight.editorActions.TextBlockTransferableData
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.CaretStateTransferableData
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiFile
@ -88,6 +89,7 @@ class PutTestAfterCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -96,6 +98,7 @@ class PutTestAfterCursorActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("p"))
val after = """
A Discovery
@ -130,10 +133,13 @@ class PutTestAfterCursorActionTest : VimTestCase() {
val editor = configureByText(before)
// Add Guard to simulate Notebook behaviour. See (VIM-2577)
val guardRange = before rangeOf "\nGUARD\n"
ApplicationManager.getApplication().runReadAction {
editor.document.createGuardedBlock(guardRange.startOffset, guardRange.endOffset)
}
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -142,6 +148,7 @@ class PutTestAfterCursorActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false,
)
}
typeText(injector.parser.parseKeys("p"))
val after = """
A Discovery
@ -168,6 +175,7 @@ class PutTestAfterCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -176,6 +184,7 @@ class PutTestAfterCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("vep"))
val after = """
A Discovery

View File

@ -8,6 +8,7 @@
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.newapi.vim
import com.maddyhome.idea.vim.state.mode.SelectionType
@ -33,6 +34,7 @@ class PutTextBeforeCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -41,6 +43,7 @@ class PutTextBeforeCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "P"))
typeText(injector.parser.parseKeys("V" + "P"))
val after = """

View File

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

View File

@ -10,6 +10,7 @@
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.newapi.vim
import com.maddyhome.idea.vim.state.mode.SelectionType
@ -78,6 +79,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -86,6 +88,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "p"))
val after = "legendar${c}y it in a legendary land"
assertState(after)
@ -101,6 +104,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -109,6 +113,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("v2e" + "2p"))
val after = "legendarylegendar${c}y in a legendary land"
assertState(after)
@ -124,6 +129,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -132,6 +138,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("v$" + "2p"))
val after = "legendarylegendar${c}y"
assertState(after)
@ -173,6 +180,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -181,6 +189,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("vb" + "p"))
val after = "I legendar${c}y it in a legendary land"
assertState(after)
@ -205,6 +214,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -213,6 +223,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "p"))
val after = """
A Discovery
@ -244,6 +255,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -252,6 +264,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "p"))
val after = """
A Discovery
@ -283,6 +296,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -291,6 +305,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "p"))
val after = """
A Discovery
@ -322,6 +337,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -330,6 +346,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("v$" + "p"))
val after = """
A Discovery
@ -562,6 +579,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -570,6 +588,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "p"))
val after = """
A Discovery
@ -609,6 +628,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -617,6 +637,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "p"))
val after = """
A Discovery
@ -658,6 +679,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -666,6 +688,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("ve" + "2p"))
val after = """
A Discovery
@ -704,7 +727,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
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)
typeText(injector.parser.parseKeys("ve" + "\"+p"))
val after = """
@ -744,7 +769,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
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)
typeText(injector.parser.parseKeys("ve" + "\"+p"))
val after = """
@ -784,6 +811,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -792,6 +820,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "p"))
val after = """
A Discovery
@ -821,6 +850,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -829,6 +859,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "2p"))
val after = """
A Discovery
@ -869,6 +900,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -877,6 +909,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "p"))
val after = """
A Discovery
@ -914,7 +947,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '*', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"*p"))
val after = """
A Discovery
@ -952,7 +987,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -990,7 +1027,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1028,7 +1067,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "Discovery", SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1061,6 +1102,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1069,6 +1111,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "p"))
val after = """
A Discovery
@ -1098,6 +1141,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1106,6 +1150,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "2p"))
val after = """
A Discovery
@ -1146,6 +1191,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1154,6 +1200,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "p"))
val after = """
A Discovery
@ -1191,7 +1238,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '*', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"*p"))
val after = """
A Discovery
@ -1229,7 +1278,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1267,7 +1318,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1305,7 +1358,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "A Discovery\n", SelectionType.LINE_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1343,6 +1398,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1351,6 +1407,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "p"))
val after = """
A Discovery
@ -1409,6 +1466,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1417,6 +1475,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "p"))
val after = """
A Discovery
@ -1481,6 +1540,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1489,6 +1549,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "2p"))
val after = """
A Discovery
@ -1549,7 +1610,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1612,7 +1675,9 @@ class PutVisualTextActionTest : VimTestCase() {
configureByText(before)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runWriteAction {
injector.registerGroup.storeText(vimEditor, context, '+', "|found|\n|l roc|\n|ere i|", SelectionType.BLOCK_WISE)
}
typeText(injector.parser.parseKeys("V" + "\"+p"))
val after = """
A Discovery
@ -1672,6 +1737,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1680,6 +1746,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "p"))
val after = """
A Discovery
@ -1709,6 +1776,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1717,6 +1785,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>3e2k" + "p"))
val after = """
A Discovery
@ -1746,6 +1815,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1754,6 +1824,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "2p"))
val after = """
A Discovery
@ -1783,6 +1854,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1791,6 +1863,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>3j$" + "p"))
val after = """
A Discovery
@ -1833,6 +1906,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1841,6 +1915,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "p"))
val after = """
A Discovery
@ -1872,6 +1947,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1880,6 +1956,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "P"))
val after = """
A Discovery
@ -1922,6 +1999,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1930,6 +2008,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "2p"))
val after = """
A Discovery
@ -1973,6 +2052,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -1981,6 +2061,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e3j" + "p"))
val after = """
A Discovery
@ -2023,6 +2104,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -2031,6 +2113,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2j$" + "p"))
val after = """
A Discovery
@ -2069,6 +2152,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -2077,6 +2161,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e2j" + "p"))
val after = """
A Discovery
@ -2116,6 +2201,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -2124,6 +2210,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2e3j" + "p"))
val after = """
A Discovery
@ -2163,6 +2250,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -2171,6 +2259,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2ej" + "p"))
val after = """
A Discovery
@ -2209,6 +2298,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -2217,6 +2307,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>elj" + "p"))
val after = """
A Discovery
@ -2257,6 +2348,7 @@ class PutVisualTextActionTest : VimTestCase() {
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runWriteAction {
registerService.storeText(
vimEditor,
context,
@ -2265,6 +2357,7 @@ class PutVisualTextActionTest : VimTestCase() {
SelectionType.BLOCK_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-V>2j$" + "p"))
val after = """
A Discovery

View File

@ -8,6 +8,7 @@
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.common.TextRange
import com.maddyhome.idea.vim.newapi.vim
@ -34,6 +35,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -42,6 +44,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("v2e" + "2gp"))
val after = "legendarylegendary$c in a legendary land"
assertState(after)
@ -55,6 +58,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -63,6 +67,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("v2e" + "gp"))
val after = """
@ -80,6 +85,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -88,6 +94,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "gp"))
val after = "legendary\n$c"
assertState(after)
@ -116,6 +123,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -124,6 +132,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "gp"))
assertState(newFile)
}
@ -171,6 +180,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -179,6 +189,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("v2e" + "gP"))
val after = """
@ -196,6 +207,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -204,6 +216,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("v2e" + "2gP"))
val after = "legendarylegendary$c in a legendary land"
assertState(after)
@ -217,6 +230,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -225,6 +239,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("v$" + "2gP"))
val after = "legendarylegendar${c}y"
assertState(after)
@ -238,6 +253,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -246,6 +262,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "gP"))
val after = "legendary\n$c"
assertState(after)
@ -385,6 +402,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
val vimEditor = editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
registerService.storeText(
vimEditor,
context,
@ -393,6 +411,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {
SelectionType.LINE_WISE,
false
)
}
typeText(injector.parser.parseKeys("<C-v>" + "h" + "gp"))
val after = """
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.LineBookmark
import com.intellij.openapi.application.ApplicationManager
import com.intellij.testFramework.PlatformTestUtil
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.createLineBookmark
@ -101,7 +102,9 @@ class MotionMarkActionTest : VimTestCase() {
""".trimIndent()
configureByText(text)
fixture.project.createLineBookmark(fixture.editor, 2, 'A')
ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
val vimMarks = injector.markService.getAllGlobalMarks()
kotlin.test.assertEquals(1, vimMarks.size)
kotlin.test.assertEquals('A', vimMarks.first().key)
@ -123,7 +126,9 @@ class MotionMarkActionTest : VimTestCase() {
BookmarksManager.getInstance(fixture.project)?.remove(bookmark!!)
fixture.project.createLineBookmark(fixture.editor, 4, 'A')
ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
}
val vimMarks = injector.markService.getAllGlobalMarks()
kotlin.test.assertEquals(1, vimMarks.size)
val mark = vimMarks.first()

View File

@ -8,6 +8,7 @@
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.newapi.vim
import org.jetbrains.plugins.ideavim.SkipNeovimReason
@ -178,7 +179,9 @@ class MotionFirstScreenLineActionTest : VimTestCase() {
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
configureByLines(50, " I found it in a legendary land")
ApplicationManager.getApplication().invokeAndWait {
addBlockInlay(fixture.editor.vim.getOffset(5, 5), true, 10)
}
setPositionAndScroll(0, 20, 10)
typeText("H")
assertPosition(0, 4)

View File

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

View File

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

View File

@ -8,6 +8,7 @@
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.TestWithoutNeovim
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
// This offset is effectively "lave${c}nder"
ApplicationManager.getApplication().invokeAndWait {
it.caretModel.primaryCaret.moveToOffset(49)
}
}
}
}

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.scroll
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Inlay
import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
@ -68,6 +69,7 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
configureByColumns(200)
val inlay = addInlay(99, false, 5)
typeText("100|", "zs")
ApplicationManager.getApplication().invokeAndWait {
val visibleArea = fixture.editor.scrollingModel.visibleArea
val textWidth = visibleArea.width - inlay.widthInPixels
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
@ -76,6 +78,7 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
assertEquals(visibleArea.x, inlay.bounds!!.x)
}
}
@Test
fun `test first screen column does not include previous inline inlay associated with preceding text`() {
@ -92,9 +95,11 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
configureByColumns(200)
val inlay = addInlay(100, false, 5)
typeText("100|", "zs")
ApplicationManager.getApplication().invokeAndWait {
val availableColumns = getAvailableColumns(inlay)
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
}
}
@Test
fun `test first screen column does not include subsequent inline inlay associated with preceding text`() {
@ -102,9 +107,11 @@ class ScrollFirstScreenColumnActionTest : VimTestCase() {
configureByColumns(200)
val inlay = addInlay(100, true, 5)
typeText("100|", "zs")
ApplicationManager.getApplication().invokeAndWait {
val availableColumns = getAvailableColumns(inlay)
assertVisibleLineBounds(0, 99, 99 + availableColumns - 1)
}
}
private fun getAvailableColumns(inlay: Inlay<*>): Int {
val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.action.scroll
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Inlay
import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.VimTestCase
@ -103,6 +104,7 @@ class ScrollLastScreenColumnActionTest : VimTestCase() {
configureByColumns(200)
val inlay = addInlay(100, true, 5)
typeText("100|", "ze")
ApplicationManager.getApplication().invokeAndWait {
val visibleArea = fixture.editor.scrollingModel.visibleArea
val textWidth = visibleArea.width - inlay.widthInPixels
val availableColumns = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
@ -115,6 +117,7 @@ class ScrollLastScreenColumnActionTest : VimTestCase() {
assertEquals(visibleArea.x + textWidth, inlayX)
assertEquals(visibleArea.x + visibleArea.width, inlayX + inlay.widthInPixels)
}
}
@Test
fun `test last screen column does not include subsequent inline inlay associated with following text`() {
@ -127,7 +130,11 @@ class ScrollLastScreenColumnActionTest : VimTestCase() {
}
private fun getAvailableColumns(inlay: Inlay<*>): Int {
var res: Int? = null
ApplicationManager.getApplication().invokeAndWait {
val textWidth = fixture.editor.scrollingModel.visibleArea.width - inlay.widthInPixels
return (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
res = (textWidth / EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
}
return res!!
}
}

View File

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

View File

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

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.ideavim.VimTestCase
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 psiFile2 = fixture.configureByText("A_Discovery2", "consectetur adipiscing elit")
ApplicationManager.getApplication().invokeAndWait {
fileManager.openFile(psiFile1.virtualFile, false)
fileManager.openFile(psiFile2.virtualFile, true)
}
assertPluginError(false)
typeText(commandToKeys("bd"))

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@
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.options
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`() {
configureByText(initialText)
val editor = fixture.editor.vim
ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = true
}
typeText(commandToKeys("2,5p"))
assertExOutput(
"""
@ -88,8 +91,10 @@ class PrintCommandTest : VimTestCase() {
|5 Sed in orci mauris.
""".trimMargin(),
)
ApplicationManager.getApplication().invokeAndWait {
injector.options(editor).number = false
}
}
@Test
fun `test with count`() {

View File

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

View File

@ -8,6 +8,7 @@
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.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
@ -189,7 +190,9 @@ class VimMultipleCursorsExtensionTest : VimTestCase() {
|dfkjsg
""".trimMargin()
val editor = configureByText(before)
ApplicationManager.getApplication().invokeAndWait {
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("<A-p>"))
@ -272,7 +275,9 @@ class VimMultipleCursorsExtensionTest : VimTestCase() {
|dfkjsg
""".trimMargin()
val editor = configureByText(before)
ApplicationManager.getApplication().invokeAndWait {
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("<A-x>"))
assertMode(Mode.VISUAL(SelectionType.CHARACTER_WISE))
@ -362,7 +367,9 @@ fun getCellType(${s}pos$se: VisualPosition): CellType {
fun `test ignores regex in search pattern`() {
val before = "test ${s}t.*st${c}$se toast tallest t.*st"
val editor = configureByText(before)
ApplicationManager.getApplication().invokeAndWait {
editor.vim.mode = Mode.VISUAL(SelectionType.CHARACTER_WISE)
}
typeText(injector.parser.parseKeys("<A-n><A-n>"))
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
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim
@ -50,8 +51,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
configureByText(text)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("griw"))
assertState("one on${c}e three")
val registerService = injector.registerGroup
@ -177,8 +180,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("3griw"))
assertState("one on${c}e four")
assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text)
@ -193,8 +198,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("griw"))
assertState("one two one four")
assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text)
@ -208,8 +215,10 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister()
.storeText(vimEditor, context, vimEditor.primaryCaret(), text rangeOf "one", SelectionType.CHARACTER_WISE, false)
}
typeText(injector.parser.parseKeys("griw" + "w" + "."))
assertState("one one on${c}e four")
assertEquals("one", registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)?.text)
@ -260,8 +269,8 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
VimPlugin.getRegister()
.storeText(
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister().storeText(
vimEditor,
context,
vimEditor.primaryCaret(),
@ -269,6 +278,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("grr"))
assertState(
"""
@ -436,6 +446,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister()
.storeText(
vimEditor,
@ -445,6 +456,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("viw" + "gr"))
assertState(
"""
@ -515,6 +527,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
configureByText(text)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
ApplicationManager.getApplication().runReadAction {
VimPlugin.getRegister()
.storeText(
vimEditor,
@ -524,6 +537,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
SelectionType.CHARACTER_WISE,
false
)
}
typeText(injector.parser.parseKeys("V" + "gr"))
assertState(
"""

View File

@ -9,6 +9,7 @@
package org.jetbrains.plugins.ideavim.group
import com.intellij.idea.TestFor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.Ref
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.action.motion.search.SearchWholeWordForwardAction
@ -915,6 +916,8 @@ class SearchGroupTest : VimTestCase() {
val project = fixture.project
val searchGroup = VimPlugin.getSearch()
val ref = Ref.create(-1)
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteIntentReadAction<Any, Throwable> {
RunnableHelper.runReadCommand(
project,
{
@ -925,6 +928,8 @@ class SearchGroupTest : VimTestCase() {
null,
null,
)
}
}
return ref.get()
}
}

View File

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

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.group.motion
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -255,6 +256,8 @@ class MotionGroup_ScrollCaretIntoViewVertically_Test : VimTestCase() {
}
private fun assertVisualLineAtMiddleOfScreen(expected: Int) {
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.impl.ConstantNode
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.group.visual.IdeaSelectionControl
import com.maddyhome.idea.vim.group.visual.VimVisualTimer
@ -691,7 +692,9 @@ class IdeaVisualControlTest : VimTestCase() {
VimListenerManager.EditorListeners.addAll()
assertMode(Mode.NORMAL())
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(5, 10)
}
waitAndAssertMode(fixture, Mode.SELECT(SelectionType.CHARACTER_WISE))
}
@ -710,7 +713,9 @@ class IdeaVisualControlTest : VimTestCase() {
VimListenerManager.EditorListeners.addAll()
assertMode(Mode.NORMAL())
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(5, 10)
}
waitAndAssertMode(fixture, Mode.VISUAL(SelectionType.CHARACTER_WISE))
}
@ -729,7 +734,9 @@ class IdeaVisualControlTest : VimTestCase() {
typeText(injector.parser.parseKeys("V"))
assertMode(Mode.VISUAL(SelectionType.LINE_WISE))
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(2, 5)
}
IdeaSelectionControl.controlNonVimSelectionChange(fixture.editor)
waitAndAssert { fixture.editor.vim.mode.selectionType == SelectionType.CHARACTER_WISE }
@ -751,11 +758,14 @@ class IdeaVisualControlTest : VimTestCase() {
startDummyTemplate()
ApplicationManager.getApplication().invokeAndWait {
VimVisualTimer.doNow()
}
typeText(injector.parser.parseKeys("<esc>V"))
assertMode(Mode.VISUAL(SelectionType.LINE_WISE))
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.selectionModel.setSelection(2, 5)
IdeaSelectionControl.controlNonVimSelectionChange(fixture.editor)
@ -763,6 +773,7 @@ class IdeaVisualControlTest : VimTestCase() {
assertMode(Mode.VISUAL(SelectionType.CHARACTER_WISE))
assertCaretsVisualAttributes()
}
}
@OptionTest(VimOption(TestOptionConstants.selectmode, limitedValues = [""]))
@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
@ -782,6 +793,8 @@ class IdeaVisualControlTest : VimTestCase() {
}
private fun startDummyTemplate() {
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runWriteIntentReadAction<Any, Throwable> {
TemplateManagerImpl.setTemplateTesting(fixture.testRootDisposable)
val templateManager = TemplateManager.getInstance(fixture.project)
val createdTemplate = templateManager.createTemplate("", "")
@ -789,3 +802,5 @@ class IdeaVisualControlTest : VimTestCase() {
templateManager.startTemplate(fixture.editor, createdTemplate)
}
}
}
}

View File

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

View File

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

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.helper
import com.intellij.openapi.application.ApplicationManager
import com.maddyhome.idea.vim.helper.EditorHelper
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
@ -21,22 +22,26 @@ class EditorHelperTest : VimTestCase() {
@Test
fun `test scroll column to left of screen`() {
configureByColumns(100)
ApplicationManager.getApplication().invokeAndWait {
EditorHelper.scrollColumnToLeftOfScreen(fixture.editor, 0, 2)
val visibleArea = fixture.editor.scrollingModel.visibleArea
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals((2 * columnWidth).roundToInt(), visibleArea.x)
}
}
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@Test
fun `test scroll column to right of screen`() {
configureByColumns(100)
val column = screenWidth + 2
ApplicationManager.getApplication().invokeAndWait {
EditorHelper.scrollColumnToRightOfScreen(fixture.editor, 0, column)
val visibleArea = fixture.editor.scrollingModel.visibleArea
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals(((column - screenWidth + 1) * columnWidth).roundToInt(), visibleArea.x)
}
}
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@Test
@ -45,11 +50,13 @@ 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
// the left, mid point, 39 columns on the right
// Put column 100 into position 41 -> offset is 59 columns
ApplicationManager.getApplication().invokeAndWait {
EditorHelper.scrollColumnToMiddleOfScreen(fixture.editor, 0, 99)
val visibleArea = fixture.editor.scrollingModel.visibleArea
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals((59 * columnWidth).roundToInt(), visibleArea.x)
}
}
@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
@Test
@ -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
// the left, mid point, 40 columns on the right
// Put column 100 into position 41 -> offset is 59 columns
ApplicationManager.getApplication().invokeAndWait {
EditorHelper.scrollColumnToMiddleOfScreen(fixture.editor, 0, 99)
val visibleArea = fixture.editor.scrollingModel.visibleArea
val columnWidth = EditorHelper.getPlainSpaceWidthFloat(fixture.editor)
assertEquals((59 * columnWidth).roundToInt(), visibleArea.x)
}
}
}

View File

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

View File

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

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -38,7 +39,9 @@ class BreakIndentOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// 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`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isUseCustomSoftWrapIndent = true
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try {
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`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isUseCustomSoftWrapIndent = true
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try {
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.lang.Language
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.impl.SettingsImpl
@ -42,7 +43,9 @@ class ColorColumnOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun openNewBufferWindow(filename: String, content: String): Editor {
// This replaces fixture.editor
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
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -100,19 +103,24 @@ class ColorColumnOptionMapperTest : VimTestCase() {
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
// of "+0", which makes Vim show a highlight column at 'textwidth' (IntelliJ shows it even if 'textwidth' is 0)
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
assertCommandOutput("set colorcolumn?", " colorcolumn=+0")
}
}
@Test
fun `test 'colorcolumn' reports '+0' at end of visual guide list`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
}
}
@Test
fun `test 'colorcolumn' option reports global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true
setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
@ -126,9 +134,11 @@ class ColorColumnOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test local 'colorcolumn' option reports global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true
setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=10,20,30,+0")
@ -142,9 +152,11 @@ class ColorColumnOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test 'colorcolumn' option reports local intellij setting if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
@ -158,9 +170,11 @@ class ColorColumnOptionMapperTest : VimTestCase() {
fixture.editor.settings.isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test local 'colorcolumn' option reports local intellij setting if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=10,20,30,+0")
@ -174,20 +188,25 @@ class ColorColumnOptionMapperTest : VimTestCase() {
fixture.editor.settings.isRightMarginShown = false
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test 'colorcolumn' does not report current visual guides if global right margin option is disabled`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isRightMarginShown = false
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test 'colorcolumn' does not report current visual guides if local right margin option is disabled`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = false
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test set 'colorcolumn' modifies local intellij setting only`() {
@ -260,8 +279,10 @@ class ColorColumnOptionMapperTest : VimTestCase() {
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
// affects the local value
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(70, 80, 90))
}
assertCommandOutput("setlocal colorcolumn?", " colorcolumn=70,80,90,+0")
assertCommandOutput("set colorcolumn?", " colorcolumn=70,80,90,+0")
assertCommandOutput("setglobal colorcolumn?", " colorcolumn=")
@ -282,6 +303,7 @@ class ColorColumnOptionMapperTest : VimTestCase() {
@Test
fun `test reset 'colorcolun' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
@ -294,9 +316,11 @@ class ColorColumnOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertFalse(fixture.editor.settings.isRightMarginShown)
}
}
@Test
fun `test reset local 'colorcolun' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isRightMarginShown = true
fixture.editor.settings.setSoftMargins(listOf(10, 20, 30))
@ -309,9 +333,11 @@ class ColorColumnOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true
assertFalse(fixture.editor.settings.isRightMarginShown)
}
}
@Test
fun `test open new window without setting ideavim option will initialise 'colorcolumn' to defaults`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true
setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=10,20,30,+0")
@ -327,9 +353,11 @@ class ColorColumnOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isRightMarginShown = false
assertCommandOutput("set colorcolumn?", " colorcolumn=")
}
}
@Test
fun `test open new window after setting ideavim option will initialise 'colorcolumn' to setglobal value`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isRightMarginShown = true
setGlobalSoftMargins(listOf(10, 20, 30))
enterCommand("set colorcolumn=40,50,60")
@ -343,6 +371,7 @@ class ColorColumnOptionMapperTest : VimTestCase() {
setGlobalSoftMargins(listOf(10, 20, 30))
assertCommandOutput("set colorcolumn?", " colorcolumn=40,50,60,+0")
}
}
@Test
fun `test setglobal value used when opening new window`() {
@ -358,11 +387,16 @@ class ColorColumnOptionMapperTest : VimTestCase() {
}
private fun getGlobalSoftMargins(): List<Int> {
var res: List<Int>? = null
ApplicationManager.getApplication().runReadAction {
val language = TextEditorImpl.getDocumentLanguage(fixture.editor)
return CodeStyle.getSettings(fixture.editor).getSoftMargins(language)
res = CodeStyle.getSettings(fixture.editor).getSoftMargins(language)
}
return res!!
}
private fun setGlobalSoftMargins(margins: List<Int>) {
ApplicationManager.getApplication().runReadAction {
val language = TextEditorImpl.getDocumentLanguage(fixture.editor)
val commonSettings = CodeStyle.getSettings(fixture.editor).getCommonSettings(language)
if (language == null || commonSettings.language == Language.ANY) {
@ -374,3 +408,4 @@ class ColorColumnOptionMapperTest : VimTestCase() {
(fixture.editor.settings as SettingsImpl).reinitSettings()
}
}
}

View File

@ -8,6 +8,7 @@
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.impl.SettingsImpl
import com.maddyhome.idea.vim.group.IjOptions
@ -32,7 +33,9 @@ class CursorLineOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -48,42 +51,52 @@ class CursorLineOptionMapperTest : VimTestCase() {
@Test
fun `test 'cursorline' defaults to global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown)
assertTrue(optionsIj().cursorline)
}
}
@Test
fun `test 'cursorline' option reports global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
}
assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown)
assertCommandOutput("set cursorline?", " cursorline")
}
@Test
fun `test local 'cursorline' option reports global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
assertTrue(EditorSettingsExternalizable.getInstance().isCaretRowShown)
assertCommandOutput("setlocal cursorline?", " cursorline")
}
}
@Test
fun `test 'cursorline' option reports local intellij setting if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isCaretRowShown = false
assertCommandOutput("set cursorline?", "nocursorline")
fixture.editor.settings.isCaretRowShown = true
assertCommandOutput("set cursorline?", " cursorline")
}
}
@Test
fun `test local 'cursorline' option reports local intellij setting if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isCaretRowShown = false
assertCommandOutput("setlocal cursorline?", "nocursorline")
fixture.editor.settings.isCaretRowShown = true
assertCommandOutput("setlocal cursorline?", " cursorline")
}
}
@Test
fun `test set 'cursorline' modifies local intellij setting only`() {
@ -184,6 +197,7 @@ class CursorLineOptionMapperTest : VimTestCase() {
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
// handling of per-window "global" values is correct.
ApplicationManager.getApplication().invokeAndWait {
(fixture.editor.settings as SettingsImpl).getState().apply { clearOverriding(this::myCaretRowShown) }
assertCommandOutput("set cursorline?", " cursorline")
@ -193,6 +207,7 @@ class CursorLineOptionMapperTest : VimTestCase() {
// Can't prove that it was copied as a default value because we can't change the global value
}
}
@Test
fun `test open new window after setting option copies value as explicitly set`() {

View File

@ -8,6 +8,7 @@
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.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
@ -40,7 +41,9 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -64,6 +67,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Test
fun `test 'number' and 'relativenumber' options reports global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("set relativenumber?", "norelativenumber")
@ -73,9 +77,11 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set number?", " number")
assertCommandOutput("set relativenumber?", " relativenumber")
}
}
@Test
fun `test local 'number' and 'relativenumber' options reports global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
@ -85,6 +91,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("setlocal number?", " number")
assertCommandOutput("setlocal relativenumber?", " relativenumber")
}
}
@Test
fun `test 'number' and 'relativenumber' options report local intellij settings if set via IDE`() {
@ -93,6 +100,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set relativenumber?", "norelativenumber")
// View | Active Editor | Show Line Numbers. There is no UI for line numeration type
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isLineNumbersShown = true
fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID
assertCommandOutput("set number?", " number")
@ -106,9 +114,11 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("set relativenumber?", " relativenumber")
}
}
@Test
fun `test local 'number' and 'relativenumber' options report local intellij settings if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isLineNumbersShown = false
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("setlocal relativenumber?", "norelativenumber")
@ -127,6 +137,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("setlocal number?", "nonumber")
assertCommandOutput("setlocal relativenumber?", " relativenumber")
}
}
@Test
fun `test set 'number' enables absolute numbers for local intellij setting only`() {
@ -234,8 +245,10 @@ class LineNumberOptionsMapperTest : VimTestCase() {
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
// affects the local value
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isLineNumbersShown = true
fixture.editor.settings.lineNumerationType = LineNumerationType.HYBRID
}
assertCommandOutput("setlocal number?", " number")
assertCommandOutput("set number?", " number")
@ -283,6 +296,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Test
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
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
injector.optionGroup.resetAllOptionsForTesting()
@ -300,10 +314,12 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("setglobal number?", "nonumber")
}
}
@Test
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
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting()
@ -319,9 +335,11 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set relativenumber?", "norelativenumber")
assertCommandOutput("setglobal relativenumber?", "norelativenumber")
}
}
@Test
fun `test reset 'number' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
fixture.editor.settings.isLineNumbersShown = false
@ -336,9 +354,12 @@ class LineNumberOptionsMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown)
}
}
@Test
fun `test reset 'relativenumber' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting() // So changing the global values does not modify IdeaVim's values
@ -356,9 +377,12 @@ class LineNumberOptionsMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown)
}
}
}
@Test
fun `test local reset 'number' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
fixture.editor.settings.isLineNumbersShown = false
@ -373,9 +397,11 @@ class LineNumberOptionsMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown)
}
}
@Test
fun `test reset local 'relativenumber' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting() // So changing the global values does not modify IdeaVim's values
@ -393,6 +419,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = false
assertTrue(fixture.editor.settings.isLineNumbersShown)
}
}
@Test
fun `test open new window without setting 'number' copies value as not-explicitly set`() {
@ -405,8 +432,10 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set number?", "nonumber")
// Changing the global setting should update the new editor
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.ABSOLUTE
}
assertCommandOutput("set number?", " number")
}
@ -414,6 +443,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
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
// handling of per-window "global" values is correct.
ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set relativenumber?", "norelativenumber")
switchToNewFile("bbb.txt", "lorem ipsum")
@ -425,6 +455,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
assertCommandOutput("set relativenumber?", " relativenumber")
}
}
@Test
fun `test open new window after setting 'number' copies value as explicitly set`() {
@ -517,6 +548,7 @@ class LineNumberOptionsMapperTest : VimTestCase() {
@Test
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
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isLineNumbersShown = true
injector.optionGroup.resetAllOptionsForTesting()
@ -535,10 +567,12 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("set number?", "nonumber")
assertCommandOutput("setglobal number?", "nonumber")
}
}
@Test
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
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().lineNumeration = LineNumerationType.RELATIVE
injector.optionGroup.resetAllOptionsForTesting()
@ -558,3 +592,4 @@ class LineNumberOptionsMapperTest : VimTestCase() {
assertCommandOutput("setglobal relativenumber?", "norelativenumber")
}
}
}

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.IjOptions
@ -31,7 +32,9 @@ class ListOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// 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`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isWhitespacesShown = true
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try {
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`() {
// Default value is false. Update the global value to something different, but make sure the Vim options are default
EditorSettingsExternalizable.getInstance().isWhitespacesShown = true
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
injector.optionGroup.resetAllOptionsForTesting()
}
}
try {
injector.optionGroup.startInitVimRc()

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -39,7 +40,9 @@ class ScrollJumpOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// 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
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -38,7 +39,9 @@ class ScrollOffOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -160,11 +163,14 @@ class ScrollOffOptionMapperTest : VimTestCase() {
fun `test setting global IDE value will update IdeaVim value`() {
enterCommand("set scrolloff=10")
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 20
assertCommandOutput("set scrolloff?", " scrolloff=20")
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertCommandOutput("setglobal scrolloff?", " scrolloff=20")
}
}
@Test
fun `test setting global IDE value will not update locally set IdeaVim value`() {
@ -199,6 +205,7 @@ class ScrollOffOptionMapperTest : VimTestCase() {
assertCommandOutput("set scrolloff?", " scrolloff=20")
// Changing the global IntelliJ setting syncs with the global Vim value
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 10
assertCommandOutput("set scrolloff?", " scrolloff=10")
@ -210,6 +217,7 @@ class ScrollOffOptionMapperTest : VimTestCase() {
assertEquals(10, EditorSettingsExternalizable.getInstance().verticalScrollOffset)
assertEquals(0, fixture.editor.settings.verticalScrollOffset)
}
}
@Test
fun `test setlocal 'scrolloff' then open new window uses value from setglobal`() {
@ -270,6 +278,7 @@ class ScrollOffOptionMapperTest : VimTestCase() {
@Test
fun `test reset 'scrolloff' to default value resets global value to intellij global value for all editors`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().verticalScrollOffset = 20
val firstEditor = fixture.editor
@ -294,6 +303,7 @@ class ScrollOffOptionMapperTest : VimTestCase() {
assertCommandOutput("setlocal scrolloff?", " scrolloff=-1")
assertEquals(15, injector.options(firstEditor.vim).scrolloff) // Equivalent to `set scrolloff?`
}
}
@Test
fun `test reset 'scrolloff' to default value resets global value to intellij global value for all editors 2`() {

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.option.overrides
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -38,7 +39,9 @@ class SideScrollOffOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// 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
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
@ -39,7 +40,9 @@ class SideScrollOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// 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
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ComponentManagerEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.fileEditor.FileEditorManager
@ -50,7 +51,9 @@ class WrapOptionMapperTest : VimTestCase() {
@Suppress("SameParameterValue")
private fun switchToNewFile(filename: String, content: String) {
// This replaces fixture.editor
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
// panel (which causes problems if our next command is `:set`). So type something (`0` is a good no-op) to give time
@ -72,39 +75,47 @@ class WrapOptionMapperTest : VimTestCase() {
@Test
fun `test 'wrap' option reports current global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap")
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("set wrap?", " wrap")
}
}
@Test
fun `test local 'wrap' option reports current global intellij setting if not explicitly set`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap")
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
assertCommandOutput("setlocal wrap?", " wrap")
}
}
@Test
fun `test 'wrap' option reports local intellij setting if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isUseSoftWraps = true
assertCommandOutput("set wrap?", " wrap")
fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap")
}
}
@Test
fun `test local 'wrap' option reports local intellij setting if set via IDE`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isUseSoftWraps = true
assertCommandOutput("setlocal wrap?", " wrap")
fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap")
}
}
@Test
fun `test set 'wrap' modifies local intellij setting only`() {
@ -132,6 +143,7 @@ class WrapOptionMapperTest : VimTestCase() {
@Test
fun `test setglobal 'wrap' option affects IdeaVim global value only`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("setglobal wrap?", " wrap") // Default for IdeaVim option is true
@ -140,6 +152,7 @@ class WrapOptionMapperTest : VimTestCase() {
assertCommandOutput("setglobal wrap?", "nowrap")
assertTrue(EditorSettingsExternalizable.getInstance().isUseSoftWraps)
}
}
@Test
fun `test set updates IdeaVim global value as well as local`() {
@ -152,11 +165,13 @@ class WrapOptionMapperTest : VimTestCase() {
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
// affects the local value
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap")
assertCommandOutput("set wrap?", "nowrap")
assertCommandOutput("setglobal wrap?", " wrap")
}
}
@Test
fun `test setting global IDE value will not update explicitly set value`() {
@ -175,6 +190,7 @@ class WrapOptionMapperTest : VimTestCase() {
@Test
fun `test setting global IDE value will update effective Vim value set during plugin startup`() {
ApplicationManager.getApplication().invokeAndWait {
try {
injector.optionGroup.startInitVimRc()
enterCommand("set nowrap")
@ -189,6 +205,7 @@ class WrapOptionMapperTest : VimTestCase() {
assertCommandOutput("set wrap?", " wrap")
assertCommandOutput("setglobal wrap?", " wrap")
}
}
@Test
fun `test setglobal does not modify effective value`() {
@ -204,6 +221,7 @@ class WrapOptionMapperTest : VimTestCase() {
@Test
fun `test reset 'wrap' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = true
fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap")
@ -216,9 +234,11 @@ class WrapOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertTrue(fixture.editor.settings.isUseSoftWraps)
}
}
@Test
fun `test reset local 'wrap' to default copies current global intellij setting`() {
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.settings.isUseSoftWraps = false
assertCommandOutput("setlocal wrap?", "nowrap")
@ -230,11 +250,13 @@ class WrapOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertTrue(fixture.editor.settings.isUseSoftWraps)
}
}
@Test
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
// handling of per-window "global" values is correct.
ApplicationManager.getApplication().invokeAndWait {
assertCommandOutput("set wrap?", " wrap")
switchToNewFile("bbb.txt", "lorem ipsum")
@ -245,6 +267,7 @@ class WrapOptionMapperTest : VimTestCase() {
EditorSettingsExternalizable.getInstance().isUseSoftWraps = false
assertCommandOutput("set wrap?", "nowrap")
}
}
@Test
fun `test open new window after setting option copies value as explicitly set`() {
@ -292,6 +315,7 @@ class WrapOptionMapperTest : VimTestCase() {
@Test
fun `test setting global IDE value will update effective Vim value in new window initialised from value set during startup`() {
ApplicationManager.getApplication().invokeAndWait {
try {
injector.optionGroup.startInitVimRc()
enterCommand("set nowrap")
@ -309,3 +333,4 @@ class WrapOptionMapperTest : VimTestCase() {
assertCommandOutput("set wrap?", " wrap")
}
}
}

View File

@ -8,6 +8,7 @@
package org.jetbrains.plugins.ideavim.regex
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.VisualPosition
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.TextRange
@ -20,8 +21,12 @@ import kotlin.test.assertEquals
class VimRegexEngineTest : VimTestCase() {
private fun findAll(pattern: String): List<TextRange> {
var result: List<TextRange>? = null
ApplicationManager.getApplication().runReadAction {
val regex = VimRegex(pattern)
return regex.findAll(fixture.editor.vim).map { it.range }
result = regex.findAll(fixture.editor.vim).map { it.range }
}
return result!!
}
@Test
@ -79,12 +84,14 @@ class VimRegexEngineTest : VimTestCase() {
configureByText("Lor${c}em ${c}Ipsum")
val editor = fixture.editor.vim
val mark = VimMark.create('m', 0, 0, editor.getPath(), editor.extractProtocol())!!
ApplicationManager.getApplication().invokeAndWait {
val secondCaret = editor.carets().maxByOrNull { it.offset }!!
secondCaret.markStorage.setMark(mark)
val result = findAll("\\%>'m\\%#.")
assertEquals(result, listOf(TextRange(6, 7)))
}
}
@Test
fun `test text at mark position`() {
@ -141,6 +148,7 @@ class VimRegexEngineTest : VimTestCase() {
val caretModel = fixture.editor.caretModel
typeText("v") // a workaround to trigger visual mode
ApplicationManager.getApplication().invokeAndWait {
caretModel.addCaret(VisualPosition(0, 2))
val caret = caretModel.getCaretAt(VisualPosition(0, 2))!!
caret.setSelection(0, 5)
@ -151,5 +159,6 @@ class VimRegexEngineTest : VimTestCase() {
val result = findAll("\\%V.\\{-}\\%#.")
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.IdeaTestFixtureFactory
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl
import com.intellij.testFramework.junit5.RunInEdt
import com.intellij.util.ui.EmptyClipboardOwner
import com.maddyhome.idea.vim.KeyHandler
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.listener.SelectionVimListenerSuppressor
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.ijOptions
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.
* 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.
*
* 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
@Deprecated(
"Use IdeaVimTestCase instead",
replaceWith = ReplaceWith("IdeaVimTestCase", "org.jetbrains.plugins.ideavim.IdeaVimTestCase")
)
abstract class VimTestCase : IdeaVimTestCase() {
object Checks {
var caretShape: Boolean = true
@ -245,8 +220,10 @@ abstract class IdeaVimTestCase {
private fun setDefaultIntelliJSettings(editor: Editor) {
// These settings don't have a global setting...
ApplicationManager.getApplication().invokeAndWait {
editor.settings.isCaretRowShown = IjOptions.cursorline.defaultValue.asBoolean()
}
}
protected open fun createFixture(factory: IdeaTestFixtureFactory): CodeInsightTestFixture {
val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR
@ -324,14 +301,18 @@ abstract class IdeaVimTestCase {
protected fun setEditorVisibleSize(width: Int, height: Int) {
val w = (width * EditorHelper.getPlainSpaceWidthFloat(fixture.editor)).roundToInt()
val h = height * fixture.editor.lineHeight
ApplicationManager.getApplication().invokeAndWait {
EditorTestUtil.setEditorVisibleSizeInPixels(fixture.editor, w, h)
}
}
protected fun setEditorVirtualSpace() {
ApplicationManager.getApplication().invokeAndWait {
// Enable virtual space at the bottom of the file and force a layout to pick up the changes
fixture.editor.settings.isAdditionalPageAtBottom = true
(fixture.editor as EditorEx).scrollPane.viewport.doLayout()
}
}
protected fun configureByText(content: String) = configureByText(PlainTextFileType.INSTANCE, content)
protected fun configureByXmlText(content: String) = configureByText(XmlFileType.INSTANCE, content)
@ -340,13 +321,16 @@ abstract class IdeaVimTestCase {
protected fun configureAndGuard(content: String) {
val ranges = extractBrackets(content)
ApplicationManager.getApplication().runReadAction {
for ((start, end) in ranges) {
fixture.editor.document.createGuardedBlock(start, end)
}
}
}
protected fun configureAndFold(content: String, @Suppress("SameParameterValue") placeholder: String) {
val ranges = extractBrackets(content)
ApplicationManager.getApplication().invokeAndWait {
fixture.editor.foldingModel.runBatchFoldingOperation {
for ((start, end) in ranges) {
val foldRegion = fixture.editor.foldingModel.addFoldRegion(start, end, placeholder)
@ -354,6 +338,7 @@ abstract class IdeaVimTestCase {
}
}
}
}
private fun extractBrackets(content: String): ArrayList<Pair<Int, Int>> {
var myContent = content.replace(c, "").replace(s, "").replace(se, "")
@ -462,6 +447,7 @@ abstract class IdeaVimTestCase {
assertTopLogicalLine(scrollToLogicalLine)
assertPosition(caretLogicalLine, caretLogicalColumn)
ApplicationManager.getApplication().invokeAndWait {
// Belt and braces. Let's make sure that the caret is fully onscreen
val bottomLogicalLine = fixture.editor.vim.visualLineToBufferLine(
EditorHelper.getVisualLineAtBottomOfScreen(fixture.editor),
@ -469,6 +455,7 @@ abstract class IdeaVimTestCase {
assertTrue(bottomLogicalLine >= caretLogicalLine)
assertTrue(caretLogicalLine >= scrollToLogicalLine)
}
}
protected fun typeText(vararg keys: String) = typeText(keys.flatMap { injector.parser.parseKeys(it) })
@ -651,26 +638,35 @@ abstract class IdeaVimTestCase {
// Use logical rather than visual lines, so we can correctly test handling of collapsed folds and soft wraps
fun assertVisibleArea(topLogicalLine: Int, bottomLogicalLine: Int) {
ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().runReadAction {
assertTopLogicalLine(topLogicalLine)
assertBottomLogicalLine(bottomLogicalLine)
}
}
}
fun assertTopLogicalLine(topLogicalLine: Int) {
ApplicationManager.getApplication().invokeAndWait {
val actualVisualTop = EditorHelper.getVisualLineAtTopOfScreen(fixture.editor)
val actualLogicalTop = fixture.editor.vim.visualLineToBufferLine(actualVisualTop)
assertEquals(topLogicalLine, actualLogicalTop, "Top logical lines don't match")
}
}
fun assertBottomLogicalLine(bottomLogicalLine: Int) {
ApplicationManager.getApplication().invokeAndWait {
val actualVisualBottom = EditorHelper.getVisualLineAtBottomOfScreen(fixture.editor)
val actualLogicalBottom = fixture.editor.vim.visualLineToBufferLine(actualVisualBottom)
assertEquals(bottomLogicalLine, actualLogicalBottom, "Bottom logical lines don't match")
}
}
fun assertVisibleLineBounds(logicalLine: Int, leftLogicalColumn: Int, rightLogicalColumn: Int) {
val visualLine = IjVimEditor(fixture.editor).bufferLineToVisualLine(logicalLine)
ApplicationManager.getApplication().invokeAndWait {
val visualLine = fixture.editor.vim.bufferLineToVisualLine(logicalLine)
val actualLeftVisualColumn = EditorHelper.getVisualColumnAtLeftOfDisplay(fixture.editor, visualLine)
val actualLeftLogicalColumn =
fixture.editor.visualToLogicalPosition(VisualPosition(visualLine, actualLeftVisualColumn)).column
@ -682,6 +678,7 @@ abstract class IdeaVimTestCase {
val actual = ScreenBounds(actualLeftLogicalColumn, actualRightLogicalColumn)
assertEquals(expected, actual)
}
}
fun assertLineCount(expected: Int) {
assertEquals(expected, fixture.editor.vim.lineCount())
@ -953,8 +950,12 @@ abstract class IdeaVimTestCase {
relatesToPrecedingText: Boolean,
@Suppress("SameParameterValue") widthInColumns: Int,
): Inlay<*> {
var inlay: Inlay<*>? = null
ApplicationManager.getApplication().invokeAndWait {
val widthInPixels = (EditorHelper.getPlainSpaceWidthFloat(fixture.editor) * widthInColumns).roundToInt()
return EditorTestUtil.addInlay(fixture.editor, offset, relatesToPrecedingText, widthInPixels)
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
@ -969,7 +970,11 @@ abstract class IdeaVimTestCase {
val widthInColumns = 10 // Arbitrary width. We don't care.
val widthInPixels = (EditorHelper.getPlainSpaceWidthFloat(fixture.editor) * widthInColumns).roundToInt()
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

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.VimCopiedText
import com.maddyhome.idea.vim.helper.RWLockLabel
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
@RWLockLabel.Readonly
fun getTransferableData(vimEditor: VimEditor, textRange: TextRange): List<Any>
fun preprocessText(

View File

@ -83,6 +83,7 @@ sealed class Command(
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
// currently has a selection and if (when we still in Visual) it was a block selection.
injector.application.runReadAction {
if (editor.primaryCaret().hasSelection() && editor.primaryCaret().lastSelectionInfo.selectionType.isBlock) {
editor.removeSecondaryCarets()
}
@ -94,6 +95,7 @@ sealed class Command(
}
}
}
}
if (argFlags.access == Access.WRITABLE && !editor.isDocumentWritable()) {
logger.info("Trying to modify readonly document")