mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 15:40:37 +02:00
Support cmd for selectmode option
This commit is contained in:
parent
3bc628417f
commit
dbcf2acce4
src/com/maddyhome/idea/vim
test/org/jetbrains/plugins/ideavim/action/motion/visual
@ -57,8 +57,6 @@ class RegisterActions {
|
||||
|
||||
private static void registerVariousModesActions() {
|
||||
final KeyGroup parser = VimPlugin.getKey();
|
||||
parser.registerAction(MappingMode.NV, "VimVisualToggleLineMode", Command.Type.OTHER_READONLY, EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE),
|
||||
new Shortcut('V'));
|
||||
parser.registerAction(MappingMode.NV, "VimVisualToggleBlockMode", Command.Type.OTHER_READONLY,
|
||||
EnumSet.of(CommandFlags.FLAG_MOT_BLOCKWISE),
|
||||
new Shortcut[]{new Shortcut(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK)),
|
||||
|
@ -25,6 +25,8 @@ import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
|
||||
import com.maddyhome.idea.vim.option.ListOption;
|
||||
import com.maddyhome.idea.vim.option.Options;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -37,9 +39,13 @@ public class VisualToggleBlockModeAction extends EditorAction {
|
||||
|
||||
private static class Handler extends EditorActionHandlerBase {
|
||||
protected boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull Command cmd) {
|
||||
final ListOption listOption = Options.getInstance().getListOption(Options.SELECTMODE);
|
||||
if (listOption != null && listOption.contains("cmd")) {
|
||||
return VimPlugin.getVisualMotion().enterSelectMode(editor, CommandState.SubMode.VISUAL_BLOCK);
|
||||
}
|
||||
|
||||
return VimPlugin.getVisualMotion()
|
||||
.toggleVisual(editor, cmd.getCount(), cmd.getRawCount(), CommandState.SubMode.VISUAL_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@ import com.maddyhome.idea.vim.command.CommandFlags;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.command.MappingMode;
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
|
||||
import com.maddyhome.idea.vim.option.ListOption;
|
||||
import com.maddyhome.idea.vim.option.Options;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -38,6 +40,11 @@ public class VisualToggleCharacterModeAction extends VimCommandAction {
|
||||
public VisualToggleCharacterModeAction() {
|
||||
super(new EditorActionHandlerBase() {
|
||||
protected boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull Command cmd) {
|
||||
final ListOption listOption = Options.getInstance().getListOption(Options.SELECTMODE);
|
||||
if (listOption != null && listOption.contains("cmd")) {
|
||||
return VimPlugin.getVisualMotion().enterSelectMode(editor, CommandState.SubMode.VISUAL_CHARACTER);
|
||||
}
|
||||
|
||||
return VimPlugin.getVisualMotion()
|
||||
.toggleVisual(editor, cmd.getCount(), cmd.getRawCount(), CommandState.SubMode.VISUAL_CHARACTER);
|
||||
}
|
||||
|
@ -16,37 +16,46 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.vim.action.motion.visual;
|
||||
package com.maddyhome.idea.vim.action.motion.visual
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.Command;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
|
||||
import com.maddyhome.idea.vim.option.ListOption;
|
||||
import com.maddyhome.idea.vim.option.Options;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.action.VimCommandAction
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.group.visual.vimForAllOrPrimaryCaret
|
||||
import com.maddyhome.idea.vim.group.visual.vimSetSelection
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
|
||||
import com.maddyhome.idea.vim.option.Options
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class VisualToggleLineModeAction extends EditorAction {
|
||||
public VisualToggleLineModeAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
private object VisualToggleLineModeActionHandler : EditorActionHandlerBase() {
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
|
||||
val listOption = Options.getInstance().getListOption(Options.SELECTMODE)
|
||||
return if (listOption != null && "cmd" in listOption) {
|
||||
VimPlugin.getVisualMotion().enterSelectMode(editor, CommandState.SubMode.VISUAL_LINE).also {
|
||||
editor.vimForAllOrPrimaryCaret { it.vimSetSelection(it.offset) }
|
||||
}
|
||||
} else VimPlugin.getVisualMotion()
|
||||
.toggleVisual(editor, cmd.count, cmd.rawCount, CommandState.SubMode.VISUAL_LINE)
|
||||
|
||||
private static class Handler extends EditorActionHandlerBase {
|
||||
protected boolean execute(@NotNull Editor editor, @NotNull DataContext context, @NotNull Command cmd) {
|
||||
final ListOption listOption = Options.getInstance().getListOption(Options.SELECTMODE);
|
||||
if (listOption != null && listOption.contains("cmd")) {
|
||||
return VimPlugin.getVisualMotion().enterSelectMode(editor, CommandState.SubMode.VISUAL_LINE);
|
||||
}
|
||||
|
||||
return VimPlugin.getVisualMotion()
|
||||
.toggleVisual(editor, cmd.getCount(), cmd.getRawCount(), CommandState.SubMode.VISUAL_LINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VisualToggleLineModeAction : VimCommandAction(VisualToggleLineModeActionHandler) {
|
||||
override fun getMappingModes(): MutableSet<MappingMode> = MappingMode.NV
|
||||
|
||||
override fun getKeyStrokesSet(): MutableSet<MutableList<KeyStroke>> = parseKeysSet("V")
|
||||
|
||||
override fun getType(): Command.Type = Command.Type.OTHER_READONLY
|
||||
|
||||
override fun getFlags(): EnumSet<CommandFlags> = EnumSet.of(CommandFlags.FLAG_MOT_LINEWISE)
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ package com.maddyhome.idea.vim.option;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.ex.ExOutputModel;
|
||||
import com.maddyhome.idea.vim.extension.VimExtension;
|
||||
@ -41,6 +42,7 @@ public class Options {
|
||||
public static final String INCREMENTAL_SEARCH = "incsearch";
|
||||
public static final String TIMEOUT = "timeout";
|
||||
public static final String VIMINFO = "viminfo";
|
||||
public static final String SELECTMODE = "selectmode";
|
||||
|
||||
/**
|
||||
* Gets the singleton instance of the options
|
||||
@ -417,7 +419,7 @@ public class Options {
|
||||
Option opt = cols.get(pos);
|
||||
String val = opt.toString();
|
||||
res.append(val);
|
||||
res.append(pad.substring(0, 20 - val.length()));
|
||||
res.append(pad, 0, 20 - val.length());
|
||||
}
|
||||
res.append("\n");
|
||||
}
|
||||
@ -426,7 +428,7 @@ public class Options {
|
||||
String val = opt.toString();
|
||||
int seg = (val.length() - 1) / width;
|
||||
for (int j = 0; j <= seg; j++) {
|
||||
res.append(val.substring(j * width, Math.min(j * width + width, val.length())));
|
||||
res.append(val, j * width, Math.min(j * width + width, val.length()));
|
||||
res.append("\n");
|
||||
}
|
||||
}
|
||||
@ -472,6 +474,7 @@ public class Options {
|
||||
addOption(new ToggleOption(TIMEOUT, "to", true));
|
||||
addOption(new ListOption(VIMINFO, "vi", new String[]{"'100", "<50", "s10", "h"}, null));
|
||||
addOption(new KeywordOption("iskeyword", "isk", new String[]{"@", "48-57", "_"}));
|
||||
addOption(new BoundListOption(SELECTMODE, "slm", ArrayUtilRt.EMPTY_STRING_ARRAY, new String[]{"mouse", "key", "cmd"}));
|
||||
|
||||
registerExtensionOptions();
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ package org.jetbrains.plugins.ideavim.action.motion.visual
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.option.Options
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
class VisualToggleBlockModeActionTest : VimTestCase() {
|
||||
@ -87,4 +89,21 @@ class VisualToggleBlockModeActionTest : VimTestCase() {
|
||||
""".trimIndent(),
|
||||
CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_BLOCK)
|
||||
}
|
||||
|
||||
fun `test selectmode option`() {
|
||||
configureByText("""
|
||||
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[long line]
|
||||
hard by the torrent of a mountain pass.
|
||||
""".trimIndent())
|
||||
Options.getInstance().getListOption(Options.SELECTMODE)?.set("cmd") ?: run {
|
||||
TestCase.fail()
|
||||
return
|
||||
}
|
||||
typeText(parseKeys("<C-V>"))
|
||||
assertState(CommandState.Mode.SELECT, CommandState.SubMode.VISUAL_BLOCK)
|
||||
}
|
||||
}
|
@ -24,6 +24,8 @@ import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviourDiffers
|
||||
import com.maddyhome.idea.vim.helper.vimSelectionStart
|
||||
import com.maddyhome.idea.vim.option.Options
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
import org.jetbrains.plugins.ideavim.rangeOf
|
||||
|
||||
@ -634,4 +636,21 @@ class VisualToggleCharacterModeActionTest : VimTestCase() {
|
||||
""".trimIndent(),
|
||||
CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_BLOCK)
|
||||
}
|
||||
|
||||
fun `test selectmode option`() {
|
||||
configureByText("""
|
||||
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[long line]
|
||||
hard by the torrent of a mountain pass.
|
||||
""".trimIndent())
|
||||
Options.getInstance().getListOption(Options.SELECTMODE)?.set("cmd") ?: run {
|
||||
TestCase.fail()
|
||||
return
|
||||
}
|
||||
typeText(parseKeys("v"))
|
||||
assertState(CommandState.Mode.SELECT, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@ package org.jetbrains.plugins.ideavim.action.motion.visual
|
||||
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.option.Options
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
|
||||
class VisualToggleLineModeActionTest : VimTestCase() {
|
||||
@ -108,4 +110,21 @@ class VisualToggleLineModeActionTest : VimTestCase() {
|
||||
""".trimIndent(),
|
||||
CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
|
||||
fun `test selectmode option`() {
|
||||
configureByText("""
|
||||
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[long line]
|
||||
hard by the torrent of a mountain pass.
|
||||
""".trimIndent())
|
||||
Options.getInstance().getListOption(Options.SELECTMODE)?.set("cmd") ?: run {
|
||||
TestCase.fail()
|
||||
return
|
||||
}
|
||||
typeText(parseKeys("V"))
|
||||
assertState(CommandState.Mode.SELECT, CommandState.SubMode.VISUAL_LINE)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user