1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-04-28 01:15:43 +02:00

Include caret shape assertions into checks

This commit is contained in:
Alex Plate 2020-12-08 09:45:26 +03:00
parent 7f1203c207
commit 21daf83fbd
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
5 changed files with 39 additions and 4 deletions
src/com/maddyhome/idea/vim
test/org/jetbrains/plugins/ideavim

View File

@ -21,6 +21,7 @@
package com.maddyhome.idea.vim.helper
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.option.OptionsManager
@ -40,12 +41,23 @@ val CommandState.Mode.isEndAllowedIgnoringOnemore: Boolean
CommandState.Mode.COMMAND, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.OP_PENDING -> false
}
val CommandState.Mode.isBlockCaret
/**
* Should this caret behave like the block caret?
* Keep in mind that in insert mode the caret can have a block shape, but it doesn't behave like the block one
* If you're looking for a shape, check [isBlockCaretShape]
*/
val CommandState.Mode.isBlockCaretBehaviour
get() = when (this) {
CommandState.Mode.VISUAL, CommandState.Mode.COMMAND, CommandState.Mode.OP_PENDING -> true
CommandState.Mode.INSERT, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.SELECT -> false
}
val CommandState.Mode.isBlockCaretShape
get() = when (this) {
CommandState.Mode.VISUAL, CommandState.Mode.COMMAND, CommandState.Mode.OP_PENDING -> true
CommandState.Mode.INSERT, CommandState.Mode.CMD_LINE, CommandState.Mode.REPLACE, CommandState.Mode.SELECT -> !VimPlugin.getEditor().isBarCursorSettings
}
val CommandState.Mode.hasVisualSelection
get() = when (this) {
CommandState.Mode.VISUAL, CommandState.Mode.SELECT -> true

View File

@ -32,7 +32,7 @@ import com.maddyhome.idea.vim.helper.EditorHelper
import com.maddyhome.idea.vim.helper.MessageHelper
import com.maddyhome.idea.vim.helper.Msg
import com.maddyhome.idea.vim.helper.hasVisualSelection
import com.maddyhome.idea.vim.helper.isBlockCaret
import com.maddyhome.idea.vim.helper.isBlockCaretBehaviour
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.helper.subMode
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
@ -491,7 +491,7 @@ object IdeaRefactorMode {
}
}
if (editor.mode.isBlockCaret) {
if (editor.mode.isBlockCaretBehaviour) {
TemplateManagerImpl.getTemplateState(editor)?.currentVariableRange?.let { segmentRange ->
if (!segmentRange.isEmpty && segmentRange.endOffset == editor.caretModel.offset && editor.caretModel.offset != 0) {
editor.caretModel.moveToOffset(editor.caretModel.offset - 1)

View File

@ -37,6 +37,9 @@ class RegisterActionsTest : VimTestCase() {
}
fun `test action in disabled plugin`() {
setupChecks {
caretShape = false
}
val keys = StringHelper.parseKeys("jklwB") // just random keys
val before = "I ${c}found it in a legendary land"
val after = "I ${c}found it in a legendary land"

View File

@ -55,6 +55,9 @@ import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
import com.maddyhome.idea.vim.helper.TestInputModel
import com.maddyhome.idea.vim.helper.inBlockSubMode
import com.maddyhome.idea.vim.helper.isBlockCaretBehaviour
import com.maddyhome.idea.vim.helper.isBlockCaretShape
import com.maddyhome.idea.vim.helper.mode
import com.maddyhome.idea.vim.key.MappingOwner
import com.maddyhome.idea.vim.key.ToKeysMappingInfo
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
@ -65,7 +68,6 @@ import com.maddyhome.idea.vim.option.OptionsManager.resetAllOptions
import com.maddyhome.idea.vim.option.ToggleOption
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
import org.junit.Assert
import java.util.*
import java.util.function.Consumer
import javax.swing.KeyStroke
@ -93,6 +95,7 @@ abstract class VimTestCase : UsefulTestCase() {
VimPlugin.getSearch().resetState()
if (!VimPlugin.isEnabled()) VimPlugin.setEnabled(true)
ideastrictmode.set()
Checks.reset()
// Make sure the entry text field gets a bounds, or we won't be able to work out caret location
ExEntryPanel.getInstance().entry.setBounds(0, 0, 100, 25)
@ -427,6 +430,7 @@ abstract class VimTestCase : UsefulTestCase() {
assertCaretsColour()
assertMode(modeAfter)
assertSubMode(subModeAfter)
if (Checks.caretShape) assertEquals(myFixture.editor.mode.isBlockCaretShape, myFixture.editor.settings.isBlockCursor)
}
protected val fileManager: FileEditorManagerEx
@ -440,6 +444,11 @@ abstract class VimTestCase : UsefulTestCase() {
return EditorTestUtil.addInlay(myFixture.editor, offset, relatesToPrecedingText, widthInColumns * columnWidth)!!
}
// Disable or enable checks for the particular test
protected inline fun setupChecks(setup: Checks.() -> Unit) {
Checks.setup()
}
companion object {
const val c = EditorTestUtil.CARET_TAG
const val s = EditorTestUtil.SELECTION_START_TAG
@ -480,4 +489,12 @@ abstract class VimTestCase : UsefulTestCase() {
fun String.dotToTab(): String = replace('.', '\t')
}
object Checks {
var caretShape: Boolean = true
fun reset() {
caretShape = true
}
}
}

View File

@ -65,6 +65,9 @@ class CommandParserTest : VimTestCase() {
}
fun `test execute in disabled state`() {
setupChecks {
caretShape = false
}
val keys = commandToKeys(">>")
val before = "I ${c}found it in a legendary land"
val after = "I ${c}found it in a legendary land"