mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 06:40:37 +02:00
Create tests for select mode toggling
This commit is contained in:
parent
bf5cab0062
commit
a133a94dbe
src/com/maddyhome/idea/vim
test/org/jetbrains/plugins/ideavim
@ -101,7 +101,7 @@ public class CommandState {
|
||||
|
||||
public static boolean inVisualBlockMode(@Nullable Editor editor) {
|
||||
final CommandState state = getInstance(editor);
|
||||
return state.getMode() == Mode.VISUAL && state.getSubMode() == SubMode.VISUAL_BLOCK;
|
||||
return state.getSubMode() == SubMode.VISUAL_BLOCK;
|
||||
}
|
||||
|
||||
public static boolean inSingleCommandMode(@Nullable Editor editor) {
|
||||
|
@ -99,7 +99,8 @@ abstract class MotionEditorActionHandler : EditorActionHandlerBase(false) {
|
||||
}
|
||||
if (!CommandState.inInsertMode(editor) &&
|
||||
!CommandState.inRepeatMode(editor) &&
|
||||
!CommandState.inVisualCharacterMode(editor)) {
|
||||
!CommandState.inVisualCharacterMode(editor) &&
|
||||
!CommandState.inSelectMode(editor)) {
|
||||
offset = EditorHelper.normalizeOffset(editor, offset, false)
|
||||
}
|
||||
preMove(editor, caret, context, cmd)
|
||||
|
@ -22,7 +22,9 @@ import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.ide.highlighter.XmlFileType;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
@ -48,6 +50,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -189,6 +192,29 @@ public abstract class VimTestCase extends UsefulTestCase {
|
||||
assertEquals(isError, VimPlugin.isError());
|
||||
}
|
||||
|
||||
protected void assertCaretsColour() {
|
||||
Color selectionColour = myFixture.getEditor().getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR);
|
||||
Color caretColour = myFixture.getEditor().getColorsScheme().getColor(EditorColors.CARET_COLOR);
|
||||
if (CommandState.inVisualBlockMode(myFixture.getEditor())) {
|
||||
CaretModel caretModel = myFixture.getEditor().getCaretModel();
|
||||
caretModel.getAllCarets().forEach(caret -> {
|
||||
if (caret != caretModel.getPrimaryCaret()) {
|
||||
assertEquals(selectionColour, caret.getVisualAttributes().getColor());
|
||||
}
|
||||
else {
|
||||
Color color = caret.getVisualAttributes().getColor();
|
||||
if (color != null) assertEquals(caretColour, color);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
myFixture.getEditor().getCaretModel().getAllCarets().forEach(caret -> {
|
||||
Color color = caret.getVisualAttributes().getColor();
|
||||
if (color != null) assertEquals(caretColour, color);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void doTest(final List<KeyStroke> keys, String before, String after) {
|
||||
configureByText(before);
|
||||
typeText(keys);
|
||||
|
@ -0,0 +1,209 @@
|
||||
package org.jetbrains.plugins.ideavim.action.motion.select
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
class SelectToggleVisualModeHandlerTest : VimTestCase() {
|
||||
fun `test switch to select mode characterwise`() {
|
||||
doTest(parseKeys("ve", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${s}found$c$se it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.SELECT)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_CHARACTER)
|
||||
}
|
||||
|
||||
fun `test switch to select mode characterwise multicaret`() {
|
||||
doTest(parseKeys("ve", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was ${c}settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${s}found$c$se it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was ${s}settled$c$se on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.SELECT)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_CHARACTER)
|
||||
}
|
||||
|
||||
fun `test switch to visual mode characterwise`() {
|
||||
doTest(parseKeys("gh", "<S-Right>".repeat(4), "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${s}foun${c}d$se it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.VISUAL)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_CHARACTER)
|
||||
}
|
||||
|
||||
fun `test switch to visual mode characterwise multicaret`() {
|
||||
doTest(parseKeys("gh", "<S-Right>".repeat(4), "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was ${c}settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${s}foun${c}d$se it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was ${s}sett${c}l${se}ed on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.VISUAL)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_CHARACTER)
|
||||
}
|
||||
|
||||
fun `test switch to select mode linewise`() {
|
||||
doTest(parseKeys("Ve", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
${s}I found$c it in a legendary land$se
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.SELECT)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
|
||||
fun `test switch to select mode linewise multicaret`() {
|
||||
doTest(parseKeys("Ve", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary$c land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was ${c}settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
${s}I found$c it in a legendary land$se
|
||||
all rocks and lavender and tufted grass,
|
||||
${s}where it was settled$c on some sodden sand$se
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.SELECT)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
|
||||
fun `test switch to visual mode linewise`() {
|
||||
doTest(parseKeys("gH", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
${s}I found it in a legendary lan${c}d$se
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.VISUAL)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
|
||||
fun `test switch to visual mode linewise multicaret`() {
|
||||
doTest(parseKeys("gH", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary$c land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was ${c}settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
${s}I found it in a legendary lan${c}d$se
|
||||
all rocks and lavender and tufted grass,
|
||||
${s}where it was settled on some sodden san${c}d$se
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.VISUAL)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
|
||||
fun `test switch to select mode blockwise`() {
|
||||
doTest(parseKeys("<C-V>ejj", "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${s}found$c$se it in a legendary land
|
||||
al${s}l roc$c${se}ks and lavender and tufted grass,
|
||||
wh${s}ere i$c${se}t was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.SELECT)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_BLOCK)
|
||||
assertCaretsColour()
|
||||
}
|
||||
|
||||
fun `test switch to visual mode blockwise`() {
|
||||
doTest(parseKeys("g<C-H>", "<S-Right>".repeat(4), "<S-Down>".repeat(2), "<C-G>"),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${c}found it in a legendary land
|
||||
all rocks and lavender and tufted grass,
|
||||
where it was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent(),
|
||||
"""
|
||||
A Discovery
|
||||
|
||||
I ${s}foun${c}d$se it in a legendary land
|
||||
al${s}l ro${c}c${se}ks and lavender and tufted grass,
|
||||
wh${s}ere ${c}i${se}t was settled on some sodden sand
|
||||
hard by the torrent of a mountain pass.""".trimIndent())
|
||||
assertMode(CommandState.Mode.VISUAL)
|
||||
assertSubMode(CommandState.SubMode.VISUAL_BLOCK)
|
||||
assertCaretsColour()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user