mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-23 13:34:03 +02:00
Unbind command state from IJ api
This commit is contained in:
parent
779c69a982
commit
2fd33e6ec2
src
main/java/com/maddyhome/idea/vim
KeyHandler.kt
action
change
macro
motion/select
command
extension
group
ChangeGroup.javaFileGroup.javaMarkGroup.javaMotionGroup.javaProcessGroup.javaRegisterGroup.java
visual
handler
helper
CaretVisualAttributesHelper.ktCommandLineHelper.ktCommandStateExtensions.ktDigraphSequence.javaModeExtensions.ktSearchHelper.java
listener
ui
vimscript/model/commands
test/java/org/jetbrains/plugins/ideavim
JavaVimTestCase.javaNeovimTesting.ktVimTestCase.kt
action
command
extension/multiplecursors
propertybased
@ -607,7 +607,7 @@ class KeyHandler {
|
||||
return true
|
||||
}
|
||||
}
|
||||
val res = editorState.processDigraphKey(key, editor.ij)
|
||||
val res = editorState.processDigraphKey(key, editor)
|
||||
if (ExEntryPanel.getInstance().isActive) {
|
||||
when (res.result) {
|
||||
DigraphResult.RES_HANDLED -> setPromptCharacterEx(if (commandBuilder.isPuttingLiteral()) '^' else key.keyChar)
|
||||
|
@ -44,7 +44,7 @@ class OperatorAction : VimActionHandler.SingleExecution() {
|
||||
if (operatorFunction != null) {
|
||||
val argument = cmd.argument
|
||||
if (argument != null) {
|
||||
if (!editor.commandState.isDotRepeatInProgress) {
|
||||
if (!editor.vim.commandState.isDotRepeatInProgress) {
|
||||
VimRepeater.Extension.argumentCaptured = argument
|
||||
}
|
||||
val saveRepeatHandler = VimRepeater.repeatHandler
|
||||
|
@ -35,7 +35,7 @@ class RepeatChangeAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_WRITABLE
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
val state = editor.commandState
|
||||
val state = editor.vim.commandState
|
||||
val lastCommand = VimRepeater.lastChangeCommand
|
||||
|
||||
if (lastCommand == null && VimRepeater.Extension.lastExtensionHandler == null) return false
|
||||
|
@ -25,6 +25,7 @@ import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.handler.VimActionHandler
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
|
||||
class ToggleRecordingAction : VimActionHandler.SingleExecution() {
|
||||
override val type: Command.Type = Command.Type.OTHER_READONLY
|
||||
@ -32,7 +33,7 @@ class ToggleRecordingAction : VimActionHandler.SingleExecution() {
|
||||
override val argumentType: Argument.Type = Argument.Type.CHARACTER
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
|
||||
return if (!editor.commandState.isRecording) {
|
||||
return if (!editor.vim.commandState.isRecording) {
|
||||
val argument = cmd.argument ?: return false
|
||||
val reg = argument.character
|
||||
VimPlugin.getRegister().startRecording(editor, reg)
|
||||
|
@ -30,6 +30,7 @@ import com.maddyhome.idea.vim.helper.inVisualMode
|
||||
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
|
||||
import com.maddyhome.idea.vim.helper.pushSelectMode
|
||||
import com.maddyhome.idea.vim.helper.pushVisualMode
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
@ -46,7 +47,7 @@ class SelectToggleVisualMode : VimActionHandler.SingleExecution() {
|
||||
|
||||
companion object {
|
||||
fun toggleMode(editor: Editor) {
|
||||
val commandState = editor.commandState
|
||||
val commandState = editor.vim.commandState
|
||||
val subMode = commandState.subMode
|
||||
val mode = commandState.mode
|
||||
commandState.popModes()
|
||||
|
@ -17,9 +17,6 @@
|
||||
*/
|
||||
package com.maddyhome.idea.vim.command
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.handler.ActionBeanClass
|
||||
import com.maddyhome.idea.vim.helper.DigraphResult
|
||||
@ -32,8 +29,10 @@ import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes
|
||||
import com.maddyhome.idea.vim.helper.updateCaretsVisualPosition
|
||||
import com.maddyhome.idea.vim.helper.vimCommandState
|
||||
import com.maddyhome.idea.vim.key.CommandPartNode
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.VimEditor
|
||||
import com.maddyhome.idea.vim.newapi.debug
|
||||
import com.maddyhome.idea.vim.newapi.ij
|
||||
import com.maddyhome.idea.vim.vimLogger
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService
|
||||
import org.jetbrains.annotations.Contract
|
||||
@ -43,7 +42,7 @@ import javax.swing.KeyStroke
|
||||
/**
|
||||
* Used to maintain state before and while entering a Vim command (operator, motion, text object, etc.)
|
||||
*/
|
||||
class CommandState private constructor(private val editor: Editor?) {
|
||||
class CommandState private constructor(private val editor: VimEditor?) {
|
||||
val commandBuilder = CommandBuilder(getKeyRootNode(MappingMode.NORMAL))
|
||||
private val modeStates = Stack<ModeState>()
|
||||
val mappingState = MappingState()
|
||||
@ -140,8 +139,8 @@ class CommandState private constructor(private val editor: Editor?) {
|
||||
|
||||
private fun onModeChanged() {
|
||||
if (editor != null) {
|
||||
editor.updateCaretsVisualAttributes()
|
||||
editor.updateCaretsVisualPosition()
|
||||
editor.ij.updateCaretsVisualAttributes()
|
||||
editor.ij.updateCaretsVisualPosition()
|
||||
} else {
|
||||
localEditors().forEach { editor ->
|
||||
editor.updateCaretsVisualAttributes()
|
||||
@ -189,7 +188,7 @@ class CommandState private constructor(private val editor: Editor?) {
|
||||
digraphSequence.startLiteralSequence()
|
||||
}
|
||||
|
||||
fun processDigraphKey(key: KeyStroke, editor: Editor): DigraphResult {
|
||||
fun processDigraphKey(key: KeyStroke, editor: VimEditor): DigraphResult {
|
||||
return digraphSequence.processKey(key, editor)
|
||||
}
|
||||
|
||||
@ -386,33 +385,24 @@ class CommandState private constructor(private val editor: Editor?) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = Logger.getInstance(CommandState::class.java.name)
|
||||
private val logger = vimLogger<CommandState>()
|
||||
private val defaultModeState = ModeState(Mode.COMMAND, SubMode.NONE)
|
||||
private val globalState = CommandState(null)
|
||||
|
||||
@JvmStatic
|
||||
fun getInstance(editor: Editor?): CommandState {
|
||||
fun getInstance(editor: VimEditor?): CommandState {
|
||||
return if (editor == null || VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL, OptionConstants.ideaglobalmodeName)) {
|
||||
globalState
|
||||
} else {
|
||||
var res = editor.vimCommandState
|
||||
var res = editor.ij.vimCommandState
|
||||
if (res == null) {
|
||||
res = CommandState(editor)
|
||||
editor.vimCommandState = res
|
||||
editor.ij.vimCommandState = res
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getInstance(editor: VimEditor): CommandState {
|
||||
return if (editor is IjVimEditor) {
|
||||
getInstance(editor.editor)
|
||||
} else {
|
||||
getInstance(null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getKeyRootNode(mappingMode: MappingMode): CommandPartNode<ActionBeanClass> {
|
||||
return VimPlugin.getKey().getKeyRoot(mappingMode)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ object VimExtensionFacade {
|
||||
/** Returns a single key stroke from the user input similar to 'getchar()'. */
|
||||
@JvmStatic
|
||||
fun inputKeyStroke(editor: Editor): KeyStroke {
|
||||
if (editor.commandState.isDotRepeatInProgress) {
|
||||
if (editor.vim.commandState.isDotRepeatInProgress) {
|
||||
val input = VimRepeater.Extension.consumeKeystroke()
|
||||
return input ?: error("Not enough keystrokes saved: ${VimRepeater.Extension.lastExtensionHandler}")
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.maddyhome.idea.vim.helper.MessageHelper;
|
||||
import com.maddyhome.idea.vim.helper.VimNlsSafe;
|
||||
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -252,7 +253,7 @@ public class VimArgTextObjExtension implements VimExtension {
|
||||
@Override
|
||||
public void execute(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
|
||||
@NotNull CommandState commandState = CommandState.getInstance(editor);
|
||||
@NotNull CommandState commandState = CommandState.getInstance(new IjVimEditor(editor));
|
||||
int count = Math.max(1, commandState.getCommandBuilder().getCount());
|
||||
|
||||
final ArgumentTextObjectHandler textObjectHandler = new ArgumentTextObjectHandler(isInner);
|
||||
|
@ -36,6 +36,7 @@ import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.extension.VimExtension;
|
||||
import com.maddyhome.idea.vim.extension.VimExtensionHandler;
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -105,7 +106,7 @@ public class CommentaryExtension implements VimExtension {
|
||||
final TextRange range = getCommentRange(editor);
|
||||
if (range == null) return false;
|
||||
|
||||
if (CommandState.getInstance(editor).getMode() != CommandState.Mode.VISUAL) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() != CommandState.Mode.VISUAL) {
|
||||
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ public class CommentaryExtension implements VimExtension {
|
||||
}
|
||||
|
||||
private @Nullable TextRange getCommentRange(@NotNull Editor editor) {
|
||||
final CommandState.Mode mode = CommandState.getInstance(editor).getMode();
|
||||
final CommandState.Mode mode = CommandState.getInstance(new IjVimEditor(editor)).getMode();
|
||||
switch (mode) {
|
||||
case COMMAND:
|
||||
return VimPlugin.getMark().getChangeMarks(editor);
|
||||
|
@ -30,7 +30,6 @@ import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.Argument
|
||||
import com.maddyhome.idea.vim.command.Command
|
||||
import com.maddyhome.idea.vim.command.CommandFlags
|
||||
import com.maddyhome.idea.vim.command.CommandState.Companion.getInstance
|
||||
import com.maddyhome.idea.vim.command.MappingMode
|
||||
import com.maddyhome.idea.vim.command.MotionType
|
||||
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
@ -49,6 +48,7 @@ import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.helper.enumSetOf
|
||||
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
||||
import com.maddyhome.idea.vim.helper.vimForEachCaret
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@ -99,11 +99,11 @@ class Matchit : VimExtension {
|
||||
private class MatchitHandler(private val reverse: Boolean) : VimExtensionHandler {
|
||||
|
||||
override fun execute(editor: Editor, context: DataContext) {
|
||||
val commandState = getInstance(editor)
|
||||
val commandState = editor.vim.commandState
|
||||
val count = commandState.commandBuilder.count
|
||||
|
||||
// Reset the command count so it doesn't transfer onto subsequent commands.
|
||||
editor.getTopLevelEditor().commandState.commandBuilder.resetCount()
|
||||
editor.getTopLevelEditor().vim.commandState.commandBuilder.resetCount()
|
||||
|
||||
// Normally we want to jump to the start of the matching pair. But when moving forward in operator
|
||||
// pending mode, we want to include the entire match. isInOpPending makes that distinction.
|
||||
|
@ -39,9 +39,11 @@ import com.maddyhome.idea.vim.group.visual.VimSelection
|
||||
import com.maddyhome.idea.vim.helper.EditorDataContext
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
import com.maddyhome.idea.vim.helper.mode
|
||||
import com.maddyhome.idea.vim.helper.subMode
|
||||
import com.maddyhome.idea.vim.helper.vimForEachCaret
|
||||
import com.maddyhome.idea.vim.key.OperatorFunction
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
class ReplaceWithRegister : VimExtension {
|
||||
@ -125,7 +127,7 @@ class ReplaceWithRegister : VimExtension {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun getRange(editor: Editor): TextRange? = when (CommandState.getInstance(editor).mode) {
|
||||
private fun getRange(editor: Editor): TextRange? = when (editor.vim.mode) {
|
||||
CommandState.Mode.COMMAND -> VimPlugin.getMark().getChangeMarks(editor)
|
||||
CommandState.Mode.VISUAL -> editor.caretModel.primaryCaret.run { TextRange(selectionStart, selectionEnd) }
|
||||
else -> null
|
||||
|
@ -29,6 +29,7 @@ import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
|
||||
import com.maddyhome.idea.vim.helper.InlayHelperKt;
|
||||
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -135,7 +136,7 @@ public class VimTextObjEntireExtension implements VimExtension {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
@NotNull CommandState commandState = CommandState.getInstance(editor);
|
||||
@NotNull CommandState commandState = CommandState.getInstance(new IjVimEditor(editor));
|
||||
int count = Math.max(1, commandState.getCommandBuilder().getCount());
|
||||
|
||||
final EntireTextObjectHandler textObjectHandler = new EntireTextObjectHandler(ignoreLeadingAndTrailing);
|
||||
|
@ -29,6 +29,7 @@ import com.maddyhome.idea.vim.handler.TextObjectActionHandler;
|
||||
import com.maddyhome.idea.vim.helper.InlayHelperKt;
|
||||
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.listener.VimListenerSuppressor;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -262,7 +263,7 @@ public class VimIndentObject implements VimExtension {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
@NotNull CommandState commandState = CommandState.getInstance(editor);
|
||||
@NotNull CommandState commandState = CommandState.getInstance(new IjVimEditor(editor));
|
||||
int count = Math.max(1, commandState.getCommandBuilder().getCount());
|
||||
|
||||
final IndentObjectHandler textObjectHandler = new IndentObjectHandler(includeAbove, includeBelow);
|
||||
|
@ -275,7 +275,7 @@ public class ChangeGroup {
|
||||
}
|
||||
|
||||
private void runEnterAction(Editor editor, @NotNull DataContext context) {
|
||||
CommandState state = CommandState.getInstance(editor);
|
||||
CommandState state = CommandState.getInstance(new IjVimEditor(editor));
|
||||
if (!state.isDotRepeatInProgress()) {
|
||||
// While repeating the enter action has been already executed because `initInsert` repeats the input
|
||||
final NativeAction action = VimInjectorKt.getInjector().getNativeActionManager().getEnterAction();
|
||||
@ -287,7 +287,7 @@ public class ChangeGroup {
|
||||
}
|
||||
|
||||
private void runEnterAboveAction(Editor editor, @NotNull DataContext context) {
|
||||
CommandState state = CommandState.getInstance(editor);
|
||||
CommandState state = CommandState.getInstance(new IjVimEditor(editor));
|
||||
if (!state.isDotRepeatInProgress()) {
|
||||
// While repeating the enter action has been already executed because `initInsert` repeats the input
|
||||
final NativeAction action = VimInjectorKt.getInjector().getNativeActionManager().getCreateLineAboveCaret();
|
||||
@ -423,7 +423,7 @@ public class ChangeGroup {
|
||||
* @param mode The mode - indicate insert or replace
|
||||
*/
|
||||
public void initInsert(@NotNull Editor editor, @NotNull DataContext context, @NotNull CommandState.Mode mode) {
|
||||
final CommandState state = CommandState.getInstance(editor);
|
||||
final CommandState state = CommandState.getInstance(new IjVimEditor(editor));
|
||||
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
for (Caret caret : caretModel.getAllCarets()) {
|
||||
@ -441,12 +441,12 @@ public class ChangeGroup {
|
||||
setInsertEditorState(editor, false);
|
||||
}
|
||||
if (cmd.getFlags().contains(CommandFlags.FLAG_NO_REPEAT_INSERT)) {
|
||||
CommandState commandState = CommandState.getInstance(editor);
|
||||
CommandState commandState = CommandState.getInstance(new IjVimEditor(editor));
|
||||
repeatInsert(editor, context, 1, false,
|
||||
new OperatorArguments(false, 1, commandState.getMode(), commandState.getSubMode()));
|
||||
}
|
||||
else {
|
||||
CommandState commandState = CommandState.getInstance(editor);
|
||||
CommandState commandState = CommandState.getInstance(new IjVimEditor(editor));
|
||||
repeatInsert(editor, context, cmd.getCount(), false,
|
||||
new OperatorArguments(false, cmd.getCount(), commandState.getMode(), commandState.getSubMode()));
|
||||
}
|
||||
@ -549,7 +549,7 @@ public class ChangeGroup {
|
||||
markGroup.setMark(editor, '^', offset);
|
||||
markGroup.setMark(editor, MarkGroup.MARK_CHANGE_END, offset);
|
||||
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.REPLACE) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.REPLACE) {
|
||||
setInsertEditorState(editor, true);
|
||||
}
|
||||
|
||||
@ -569,7 +569,7 @@ public class ChangeGroup {
|
||||
repeatInsert(editor, context, cnt == 0 ? 0 : cnt - 1, true, operatorArguments);
|
||||
}
|
||||
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.INSERT) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.INSERT) {
|
||||
updateLastInsertedTextRegister();
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ public class ChangeGroup {
|
||||
offset = editor.getCaretModel().getPrimaryCaret().getOffset();
|
||||
markGroup.setMark(editor, MarkGroup.MARK_CHANGE_POS, offset);
|
||||
|
||||
CommandState.getInstance(editor).popModes();
|
||||
CommandState.getInstance(new IjVimEditor(editor)).popModes();
|
||||
exitAllSingleCommandInsertModes(editor);
|
||||
}
|
||||
|
||||
@ -591,7 +591,7 @@ public class ChangeGroup {
|
||||
* @param context The data context
|
||||
*/
|
||||
public void processEnter(@NotNull Editor editor, @NotNull DataContext context) {
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.REPLACE) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.REPLACE) {
|
||||
setInsertEditorState(editor, true);
|
||||
}
|
||||
final KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
|
||||
@ -601,7 +601,7 @@ public class ChangeGroup {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.REPLACE) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.REPLACE) {
|
||||
setInsertEditorState(editor, false);
|
||||
}
|
||||
}
|
||||
@ -723,7 +723,7 @@ public class ChangeGroup {
|
||||
final EditorEx editorEx = ObjectUtils.tryCast(editor, EditorEx.class);
|
||||
if (editorEx == null) return;
|
||||
editorEx.setInsertMode(!editorEx.isInsertMode());
|
||||
CommandState.getInstance(editor).toggleInsertOverwrite();
|
||||
CommandState.getInstance(new IjVimEditor(editor)).toggleInsertOverwrite();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -796,7 +796,7 @@ public class ChangeGroup {
|
||||
* @param editor The editor to put into NORMAL mode for one command
|
||||
*/
|
||||
public void processSingleCommand(@NotNull Editor editor) {
|
||||
CommandState.getInstance(editor).pushModes(CommandState.Mode.INSERT_NORMAL, CommandState.SubMode.NONE);
|
||||
CommandState.getInstance(new IjVimEditor(editor)).pushModes(CommandState.Mode.INSERT_NORMAL, CommandState.SubMode.NONE);
|
||||
clearStrokes(editor);
|
||||
}
|
||||
|
||||
@ -1980,9 +1980,9 @@ public class ChangeGroup {
|
||||
|
||||
private void exitAllSingleCommandInsertModes(@NotNull Editor editor) {
|
||||
while (CommandStateHelper.inSingleCommandMode(editor)) {
|
||||
CommandState.getInstance(editor).popModes();
|
||||
CommandState.getInstance(new IjVimEditor(editor)).popModes();
|
||||
if (CommandStateHelper.inInsertMode(editor)) {
|
||||
CommandState.getInstance(editor).popModes();
|
||||
CommandState.getInstance(new IjVimEditor(editor)).popModes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,12 @@ import com.maddyhome.idea.vim.VimInjectorKt;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.helper.*;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelperRt;
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper;
|
||||
import com.maddyhome.idea.vim.helper.SearchHelper;
|
||||
import com.maddyhome.idea.vim.newapi.IjExecutionContext;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.newapi.NativeAction;
|
||||
import com.maddyhome.idea.vim.newapi.NativeActionKt;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
|
||||
@ -286,7 +290,7 @@ public class FileGroup {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Document doc = editor.getDocument();
|
||||
|
||||
if (CommandState.getInstance(editor).getMode() != CommandState.Mode.VISUAL) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() != CommandState.Mode.VISUAL) {
|
||||
LogicalPosition lp = editor.getCaretModel().getLogicalPosition();
|
||||
int col = editor.getCaretModel().getOffset() - doc.getLineStartOffset(lp.line);
|
||||
int endoff = doc.getLineEndOffset(lp.line);
|
||||
|
@ -46,6 +46,7 @@ import com.maddyhome.idea.vim.common.*;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.helper.HelperKt;
|
||||
import com.maddyhome.idea.vim.helper.SearchHelper;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService;
|
||||
import org.jdom.Element;
|
||||
@ -592,7 +593,7 @@ public class MarkGroup implements PersistentStateComponent<Element> {
|
||||
int markLineStartOff = EditorHelper.getLineStartOffset(editor, mark.getLogicalLine());
|
||||
int markLineEndOff = EditorHelper.getLineEndOffset(editor, mark.getLogicalLine(), true);
|
||||
|
||||
Command command = CommandState.getInstance(editor).getExecutingCommand();
|
||||
Command command = CommandState.getInstance(new IjVimEditor(editor)).getExecutingCommand();
|
||||
// If text is being changed from the start of the mark line (a special case for mark deletion)
|
||||
boolean changeFromMarkLineStart = command != null && command.getType() == Command.Type.CHANGE
|
||||
&& delStartOff == markLineStartOff;
|
||||
|
@ -878,7 +878,7 @@ public class MotionGroup {
|
||||
}
|
||||
|
||||
private static int getScrollJump(@NotNull Editor editor, int height) {
|
||||
final EnumSet<CommandFlags> flags = CommandState.getInstance(editor).getExecutingCommandFlags();
|
||||
final EnumSet<CommandFlags> flags = CommandState.getInstance(new IjVimEditor(editor)).getExecutingCommandFlags();
|
||||
final boolean scrollJump = !flags.contains(CommandFlags.FLAG_IGNORE_SCROLL_JUMP);
|
||||
|
||||
// Default value is 1. Zero is a valid value, but we normalise to 1 - we always want to scroll at least one line
|
||||
@ -903,7 +903,7 @@ public class MotionGroup {
|
||||
final int halfWidth = getApproximateScreenWidth(editor) / 2;
|
||||
final int scrollOffset = getNormalizedSideScrollOffset(editor);
|
||||
|
||||
final EnumSet<CommandFlags> flags = CommandState.getInstance(editor).getExecutingCommandFlags();
|
||||
final EnumSet<CommandFlags> flags = CommandState.getInstance(new IjVimEditor(editor)).getExecutingCommandFlags();
|
||||
final boolean allowSidescroll = !flags.contains(CommandFlags.FLAG_IGNORE_SIDE_SCROLL_JUMP);
|
||||
int sidescroll = ((VimInt) VimPlugin.getOptionService().getOptionValue(new OptionService.Scope.LOCAL(new IjVimEditor(editor)), OptionConstants.sidescrollName, OptionConstants.sidescrollName)).getValue();
|
||||
|
||||
@ -974,7 +974,7 @@ public class MotionGroup {
|
||||
boolean isBig) {
|
||||
int dir = 1;
|
||||
boolean selection = false;
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.VISUAL) {
|
||||
if (UserDataManager.getVimSelectionStart(caret) > caret.getOffset()) {
|
||||
dir = -1;
|
||||
}
|
||||
@ -1484,7 +1484,7 @@ public class MotionGroup {
|
||||
if (fileEditor instanceof TextEditor) {
|
||||
final Editor editor = ((TextEditor)fileEditor).getEditor();
|
||||
ExOutputModel.getInstance(editor).clear();
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.VISUAL) {
|
||||
ModeHelper.exitVisualMode(editor);
|
||||
KeyHandler.getInstance().reset(new IjVimEditor(editor));
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class ProcessGroup {
|
||||
if (editor.isOneLineMode()) return;
|
||||
|
||||
String initText = getRange(editor, cmd);
|
||||
CommandState.getInstance(editor).pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE);
|
||||
CommandState.getInstance(new IjVimEditor(editor)).pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE);
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.activate(editor, context, ":", initText, 1);
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class ProcessGroup {
|
||||
panel.deactivate(true);
|
||||
boolean res = true;
|
||||
try {
|
||||
CommandState.getInstance(editor).popModes();
|
||||
CommandState.getInstance(new IjVimEditor(editor)).popModes();
|
||||
|
||||
logger.debug("processing command");
|
||||
|
||||
@ -146,7 +146,7 @@ public class ProcessGroup {
|
||||
}
|
||||
|
||||
public void cancelExEntry(final @NotNull Editor editor, boolean resetCaret) {
|
||||
CommandState.getInstance(editor).popModes();
|
||||
CommandState.getInstance(new IjVimEditor(editor)).popModes();
|
||||
KeyHandler.getInstance().reset(new IjVimEditor(editor));
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.deactivate(true, resetCaret);
|
||||
@ -154,14 +154,14 @@ public class ProcessGroup {
|
||||
|
||||
public void startFilterCommand(@NotNull Editor editor, DataContext context, @NotNull Command cmd) {
|
||||
String initText = getRange(editor, cmd) + "!";
|
||||
CommandState.getInstance(editor).pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE);
|
||||
CommandState.getInstance(new IjVimEditor(editor)).pushModes(CommandState.Mode.CMD_LINE, CommandState.SubMode.NONE);
|
||||
ExEntryPanel panel = ExEntryPanel.getInstance();
|
||||
panel.activate(editor, context, ":", initText, 1);
|
||||
}
|
||||
|
||||
private @NotNull String getRange(Editor editor, @NotNull Command cmd) {
|
||||
String initText = "";
|
||||
if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
|
||||
if (CommandState.getInstance(new IjVimEditor(editor)).getMode() == CommandState.Mode.VISUAL) {
|
||||
initText = "'<,'>";
|
||||
}
|
||||
else if (cmd.getRawCount() > 0) {
|
||||
|
@ -56,6 +56,7 @@ import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase;
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
||||
import com.maddyhome.idea.vim.helper.StringHelper;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.ui.ClipboardHandler;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString;
|
||||
@ -375,7 +376,7 @@ public class RegisterGroup implements PersistentStateComponent<Element> {
|
||||
}
|
||||
|
||||
private boolean isSmallDeletionSpecialCase(Editor editor) {
|
||||
Command currentCommand = CommandState.getInstance(editor).getExecutingCommand();
|
||||
Command currentCommand = CommandState.getInstance(new IjVimEditor(editor)).getExecutingCommand();
|
||||
if (currentCommand != null) {
|
||||
Argument argument = currentCommand.getArgument();
|
||||
if (argument != null) {
|
||||
@ -460,7 +461,7 @@ public class RegisterGroup implements PersistentStateComponent<Element> {
|
||||
|
||||
public boolean startRecording(Editor editor, char register) {
|
||||
if (RECORDABLE_REGISTERS.indexOf(register) != -1) {
|
||||
CommandState.getInstance(editor).setRecording(true);
|
||||
CommandState.getInstance(new IjVimEditor(editor)).setRecording(true);
|
||||
recordRegister = register;
|
||||
recordList = new ArrayList<>();
|
||||
return true;
|
||||
@ -506,7 +507,7 @@ public class RegisterGroup implements PersistentStateComponent<Element> {
|
||||
reg.addKeys(recordList);
|
||||
}
|
||||
}
|
||||
CommandState.getInstance(editor).setRecording(false);
|
||||
CommandState.getInstance(new IjVimEditor(editor)).setRecording(false);
|
||||
}
|
||||
|
||||
recordRegister = 0;
|
||||
|
@ -80,13 +80,13 @@ object IdeaSelectionControl {
|
||||
return@singleTask
|
||||
}
|
||||
|
||||
logger.debug("Some carets have selection. State before adjustment: ${editor.commandState.toSimpleString()}")
|
||||
logger.debug("Some carets have selection. State before adjustment: ${editor.vim.commandState.toSimpleString()}")
|
||||
|
||||
editor.popAllModes()
|
||||
|
||||
activateMode(editor, chooseSelectionMode(editor, selectionSource, true))
|
||||
} else {
|
||||
logger.debug("None of carets have selection. State before adjustment: ${editor.commandState.toSimpleString()}")
|
||||
logger.debug("None of carets have selection. State before adjustment: ${editor.vim.commandState.toSimpleString()}")
|
||||
if (editor.inVisualMode) editor.exitVisualMode()
|
||||
if (editor.inSelectMode) editor.exitSelectMode(false)
|
||||
|
||||
|
@ -56,7 +56,7 @@ class VisualMotionGroup {
|
||||
|
||||
editor.caretModel.removeSecondaryCarets()
|
||||
|
||||
editor.commandState.pushModes(CommandState.Mode.VISUAL, lastSelectionType.toSubMode())
|
||||
editor.vim.commandState.pushModes(CommandState.Mode.VISUAL, lastSelectionType.toSubMode())
|
||||
|
||||
val primaryCaret = editor.caretModel.primaryCaret
|
||||
primaryCaret.vimSetSelection(visualMarks.startOffset, visualMarks.endOffset - 1, true)
|
||||
@ -125,7 +125,7 @@ class VisualMotionGroup {
|
||||
if (rawCount > 0) {
|
||||
val primarySubMode = editor.caretModel.primaryCaret.vimLastVisualOperatorRange?.type?.toSubMode()
|
||||
?: subMode
|
||||
editor.commandState.pushVisualMode(primarySubMode)
|
||||
editor.vim.commandState.pushVisualMode(primarySubMode)
|
||||
|
||||
editor.vimForEachCaret {
|
||||
val range = it.vimLastVisualOperatorRange ?: VisualChange.default(subMode)
|
||||
@ -138,7 +138,7 @@ class VisualMotionGroup {
|
||||
it.vimSetSelection(it.offset, end, true)
|
||||
}
|
||||
} else {
|
||||
editor.commandState.pushVisualMode(subMode)
|
||||
editor.vim.commandState.pushVisualMode(subMode)
|
||||
editor.vimForEachCaret { it.vimSetSelection(it.offset) }
|
||||
}
|
||||
return true
|
||||
@ -164,9 +164,9 @@ class VisualMotionGroup {
|
||||
val autodetectedMode = autodetectVisualSubmode(editor)
|
||||
|
||||
if (editor.inVisualMode) {
|
||||
editor.commandState.popModes()
|
||||
editor.vim.commandState.popModes()
|
||||
}
|
||||
editor.commandState.pushModes(CommandState.Mode.VISUAL, autodetectedMode)
|
||||
editor.vim.commandState.pushModes(CommandState.Mode.VISUAL, autodetectedMode)
|
||||
if (autodetectedMode == CommandState.SubMode.VISUAL_BLOCK) {
|
||||
val (start, end) = blockModeStartAndEnd(editor)
|
||||
editor.caretModel.removeSecondaryCarets()
|
||||
@ -207,7 +207,7 @@ class VisualMotionGroup {
|
||||
*/
|
||||
fun enterVisualMode(editor: Editor, subMode: CommandState.SubMode? = null): Boolean {
|
||||
val autodetectedSubMode = subMode ?: autodetectVisualSubmode(editor)
|
||||
editor.commandState.pushModes(CommandState.Mode.VISUAL, autodetectedSubMode)
|
||||
editor.vim.commandState.pushModes(CommandState.Mode.VISUAL, autodetectedSubMode)
|
||||
if (autodetectedSubMode == CommandState.SubMode.VISUAL_BLOCK) {
|
||||
editor.caretModel.primaryCaret.run { vimSelectionStart = vimLeadSelectionOffset }
|
||||
} else {
|
||||
@ -217,7 +217,7 @@ class VisualMotionGroup {
|
||||
}
|
||||
|
||||
fun enterSelectMode(editor: Editor, subMode: CommandState.SubMode): Boolean {
|
||||
editor.commandState.pushSelectMode(subMode)
|
||||
editor.vim.commandState.pushSelectMode(subMode)
|
||||
editor.vimForEachCaret { it.vimSelectionStart = it.vimLeadSelectionOffset }
|
||||
return true
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.maddyhome.idea.vim.helper.StringHelper
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.helper.getTopLevelEditor
|
||||
import com.maddyhome.idea.vim.helper.noneOfEnum
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.util.*
|
||||
import javax.swing.KeyStroke
|
||||
@ -94,7 +95,7 @@ abstract class EditorActionHandlerBase(private val myRunForEachCaret: Boolean) {
|
||||
val topLevelEditor = editor.getTopLevelEditor()
|
||||
logger.debug("Execute command with handler: " + this.javaClass.name)
|
||||
|
||||
val cmd = topLevelEditor.commandState.executingCommand ?: run {
|
||||
val cmd = topLevelEditor.vim.commandState.executingCommand ?: run {
|
||||
VimPlugin.indicateError()
|
||||
return
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ import com.maddyhome.idea.vim.helper.vimLastColumn
|
||||
import com.maddyhome.idea.vim.helper.vimLastSelectionType
|
||||
import com.maddyhome.idea.vim.helper.vimLastVisualOperatorRange
|
||||
import com.maddyhome.idea.vim.helper.vimSelectionStart
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
|
||||
/**
|
||||
* @author Alex Plate
|
||||
@ -228,7 +229,7 @@ sealed class VisualOperatorActionHandler : EditorActionHandlerBase(false) {
|
||||
}
|
||||
else -> this.caretModel.allCarets.associateWith { caret ->
|
||||
|
||||
val subMode = this.commandState.subMode
|
||||
val subMode = this.vim.commandState.subMode
|
||||
VimSimpleSelection.createWithNative(
|
||||
caret.vimSelectionStart,
|
||||
caret.offset,
|
||||
|
@ -27,6 +27,7 @@ import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.OptionChangeListener
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.helpers.GuiCursorMode
|
||||
@ -68,7 +69,7 @@ fun removeCaretsVisualAttributes(editor: Editor) {
|
||||
}
|
||||
|
||||
fun Editor.guicursorMode(): GuiCursorMode {
|
||||
if (this.commandState.isReplaceCharacter) {
|
||||
if (this.vim.commandState.isReplaceCharacter) {
|
||||
// Can be true for NORMAL and VISUAL
|
||||
return GuiCursorMode.REPLACE
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.action.change.VimRepeater
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.ui.ModalEntry
|
||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
|
||||
import java.awt.event.KeyEvent
|
||||
@ -31,7 +32,7 @@ import javax.swing.KeyStroke
|
||||
class CommandLineHelper {
|
||||
|
||||
fun inputString(editor: Editor, prompt: String, finishOn: Char?): String? {
|
||||
if (editor.commandState.isDotRepeatInProgress) {
|
||||
if (editor.vim.commandState.isDotRepeatInProgress) {
|
||||
val input = VimRepeater.Extension.consumeString()
|
||||
return input ?: error("Not enough strings saved: ${VimRepeater.Extension.lastExtensionHandler}")
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.newapi.VimEditor
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService
|
||||
@ -73,15 +74,15 @@ val CommandState.Mode.hasVisualSelection
|
||||
}
|
||||
|
||||
val Editor.mode
|
||||
get() = this.commandState.mode
|
||||
get() = this.vim.commandState.mode
|
||||
|
||||
val VimEditor.mode
|
||||
get() = this.commandState.mode
|
||||
|
||||
var Editor.subMode
|
||||
get() = this.commandState.subMode
|
||||
get() = this.vim.commandState.subMode
|
||||
set(value) {
|
||||
this.commandState.subMode = value
|
||||
this.vim.commandState.subMode = value
|
||||
}
|
||||
|
||||
var VimEditor.subMode
|
||||
@ -104,7 +105,7 @@ val Editor.inInsertMode
|
||||
|
||||
@get:JvmName("inRepeatMode")
|
||||
val Editor.inRepeatMode
|
||||
get() = this.commandState.isDotRepeatInProgress
|
||||
get() = this.vim.commandState.isDotRepeatInProgress
|
||||
|
||||
@get:JvmName("inVisualMode")
|
||||
val Editor.inVisualMode
|
||||
@ -143,10 +144,6 @@ val CommandState.Mode.inSingleNormalMode: Boolean
|
||||
else -> false
|
||||
}
|
||||
|
||||
@get:JvmName("commandState")
|
||||
val Editor.commandState
|
||||
get() = CommandState.getInstance(this)
|
||||
|
||||
val VimEditor.commandState
|
||||
get() = CommandState.getInstance(this)
|
||||
|
||||
|
@ -20,9 +20,9 @@ package com.maddyhome.idea.vim.helper;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.newapi.VimEditor;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants;
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -78,12 +78,12 @@ public class DigraphSequence {
|
||||
return DigraphResult.HANDLED_LITERAL;
|
||||
}
|
||||
|
||||
public @NotNull DigraphResult processKey(@NotNull KeyStroke key, @NotNull Editor editor) {
|
||||
public @NotNull DigraphResult processKey(@NotNull KeyStroke key, @NotNull VimEditor editor) {
|
||||
switch (digraphState) {
|
||||
case DIG_STATE_PENDING:
|
||||
logger.debug("DIG_STATE_PENDING");
|
||||
if (key.getKeyCode() == KeyEvent.VK_BACK_SPACE
|
||||
&& VimPlugin.getOptionService().isSet(new OptionService.Scope.LOCAL(new IjVimEditor(editor)), OptionConstants.digraphName, OptionConstants.digraphName)) {
|
||||
&& VimPlugin.getOptionService().isSet(new OptionService.Scope.LOCAL(editor), OptionConstants.digraphName, OptionConstants.digraphName)) {
|
||||
digraphState = DIG_STATE_BACK_SPACE;
|
||||
}
|
||||
else if (key.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
|
||||
@ -232,7 +232,7 @@ public class DigraphSequence {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
// The key we received isn't part of the literal, so post it to be handled after we've handled the literal.
|
||||
// This requires swing, so we can't run it in tests.
|
||||
VimPlugin.getMacro().postKey(key, editor);
|
||||
VimPlugin.getMacro().postKey(key, ((IjVimEditor)editor).getEditor());
|
||||
}
|
||||
|
||||
return DigraphResult.done(code);
|
||||
|
@ -32,12 +32,13 @@ import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
|
||||
import com.maddyhome.idea.vim.newapi.IjVimCaret
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
import com.maddyhome.idea.vim.newapi.VimEditor
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
|
||||
/**
|
||||
* Pop all modes, but leave editor state. E.g. editor selection is not removed.
|
||||
*/
|
||||
fun Editor.popAllModes() {
|
||||
val commandState = this.commandState
|
||||
val commandState = this.vim.commandState
|
||||
while (commandState.mode != CommandState.Mode.COMMAND) {
|
||||
commandState.popModes()
|
||||
}
|
||||
@ -63,7 +64,7 @@ fun Editor.exitVisualMode() {
|
||||
|
||||
this.subMode = CommandState.SubMode.NONE
|
||||
|
||||
this.commandState.popModes()
|
||||
this.vim.commandState.popModes()
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +72,7 @@ fun Editor.exitVisualMode() {
|
||||
fun Editor.exitSelectMode(adjustCaretPosition: Boolean) {
|
||||
if (!this.inSelectMode) return
|
||||
|
||||
this.commandState.popModes()
|
||||
this.vim.commandState.popModes()
|
||||
SelectionVimListenerSuppressor.lock().use {
|
||||
this.caretModel.allCarets.forEach {
|
||||
it.removeSelection()
|
||||
|
@ -34,6 +34,7 @@ import com.maddyhome.idea.vim.VimPlugin;
|
||||
import com.maddyhome.idea.vim.command.CommandState;
|
||||
import com.maddyhome.idea.vim.common.CharacterPosition;
|
||||
import com.maddyhome.idea.vim.common.TextRange;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import com.maddyhome.idea.vim.regexp.CharPointer;
|
||||
import com.maddyhome.idea.vim.regexp.RegExp;
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType;
|
||||
@ -891,7 +892,7 @@ public class SearchHelper {
|
||||
selectionEndWithoutNewline++;
|
||||
}
|
||||
|
||||
final CommandState.Mode mode = CommandState.getInstance(editor).getMode();
|
||||
final CommandState.Mode mode = CommandState.getInstance(new IjVimEditor(editor)).getMode();
|
||||
if (mode == CommandState.Mode.VISUAL) {
|
||||
if (closingTagTextRange.getStartOffset() == selectionEndWithoutNewline &&
|
||||
openingTag.getEndOffset() == selectionStart) {
|
||||
|
@ -88,7 +88,7 @@ object IdeaSpecifics {
|
||||
}
|
||||
) {
|
||||
editor?.let {
|
||||
val commandState = it.commandState
|
||||
val commandState = it.vim.commandState
|
||||
while (commandState.mode != CommandState.Mode.COMMAND) {
|
||||
commandState.popModes()
|
||||
}
|
||||
|
@ -31,9 +31,10 @@ import com.intellij.openapi.wm.impl.status.EditorBasedWidget
|
||||
import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
|
||||
import com.intellij.util.Consumer
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
import com.maddyhome.idea.vim.helper.VimNlsSafe
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimDataType
|
||||
import com.maddyhome.idea.vim.vimscript.model.options.OptionChangeListener
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants
|
||||
@ -69,7 +70,7 @@ object ShowCmd {
|
||||
fun getFullText(editor: Editor?): String {
|
||||
if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL, OptionConstants.showcmdName) || editor == null || editor.isDisposed) return ""
|
||||
|
||||
val editorState = CommandState.getInstance(editor)
|
||||
val editorState = editor.vim.commandState
|
||||
return StringHelper.toPrintableCharacters(editorState.commandBuilder.keys + editorState.mappingState.keys)
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import com.maddyhome.idea.vim.command.OperatorArguments
|
||||
import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.helper.EditorHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.stringToKeys
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.helper.exitInsertMode
|
||||
import com.maddyhome.idea.vim.helper.exitSelectMode
|
||||
import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
@ -53,7 +54,7 @@ data class NormalCommand(val ranges: Ranges, val argument: String) : Command.Sin
|
||||
argument = argument.substring(1)
|
||||
}
|
||||
|
||||
val commandState = CommandState.getInstance(editor)
|
||||
val commandState = editor.vim.commandState
|
||||
val rangeUsed = ranges.size() != 0
|
||||
when (editor.mode) {
|
||||
CommandState.Mode.VISUAL -> {
|
||||
|
@ -108,7 +108,7 @@ public abstract class JavaVimTestCase extends JavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void assertMode(@NotNull CommandState.Mode expectedMode) {
|
||||
final CommandState.Mode mode = CommandState.getInstance(myFixture.getEditor()).getMode();
|
||||
final CommandState.Mode mode = CommandState.getInstance(new IjVimEditor(myFixture.getEditor())).getMode();
|
||||
assertEquals(expectedMode, mode);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ import com.maddyhome.idea.vim.common.CharacterPosition
|
||||
import com.maddyhome.idea.vim.group.RegisterGroup
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.junit.Assert.assertEquals
|
||||
|
||||
internal object NeovimTesting {
|
||||
@ -145,7 +146,7 @@ internal object NeovimTesting {
|
||||
}
|
||||
|
||||
private fun assertMode(editor: Editor) {
|
||||
val ideavimState = editor.commandState.toVimNotation()
|
||||
val ideavimState = editor.vim.commandState.toVimNotation()
|
||||
val neovimState = neovimApi.mode.get().mode
|
||||
assertEquals(neovimState, ideavimState)
|
||||
}
|
||||
|
@ -65,7 +65,9 @@ import com.maddyhome.idea.vim.helper.buildGreater212
|
||||
import com.maddyhome.idea.vim.helper.getShape
|
||||
import com.maddyhome.idea.vim.helper.guicursorMode
|
||||
import com.maddyhome.idea.vim.helper.inBlockSubMode
|
||||
import com.maddyhome.idea.vim.helper.mode
|
||||
import com.maddyhome.idea.vim.helper.shape
|
||||
import com.maddyhome.idea.vim.helper.subMode
|
||||
import com.maddyhome.idea.vim.helper.thickness
|
||||
import com.maddyhome.idea.vim.key.MappingOwner
|
||||
import com.maddyhome.idea.vim.key.ToKeysMappingInfo
|
||||
@ -444,12 +446,12 @@ abstract class VimTestCase : UsefulTestCase() {
|
||||
}
|
||||
|
||||
fun assertMode(expectedMode: CommandState.Mode) {
|
||||
val mode = CommandState.getInstance(myFixture.editor).mode
|
||||
val mode = myFixture.editor.mode
|
||||
Assert.assertEquals(expectedMode, mode)
|
||||
}
|
||||
|
||||
fun assertSubMode(expectedSubMode: SubMode) {
|
||||
val subMode = CommandState.getInstance(myFixture.editor).subMode
|
||||
val subMode = myFixture.editor.subMode
|
||||
Assert.assertEquals(expectedSubMode, subMode)
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,10 @@ package org.jetbrains.plugins.ideavim.action
|
||||
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState.Companion.getInstance
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionConstants
|
||||
import com.maddyhome.idea.vim.vimscript.services.OptionService
|
||||
import junit.framework.TestCase
|
||||
@ -36,7 +37,7 @@ class MacroActionTest : VimTestCase() {
|
||||
// |q|
|
||||
fun testRecordMacro() {
|
||||
val editor = typeTextInFile(parseKeys("qa", "3l", "q"), "on<caret>e two three\n")
|
||||
val commandState = getInstance(editor)
|
||||
val commandState = editor.vim.commandState
|
||||
assertFalse(commandState.isRecording)
|
||||
val registerGroup = VimPlugin.getRegister()
|
||||
val register = registerGroup.getRegister('a')
|
||||
|
@ -20,6 +20,7 @@ package org.jetbrains.plugins.ideavim.command
|
||||
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.plugins.ideavim.SkipNeovimReason
|
||||
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
@ -28,7 +29,7 @@ class CommandStateTest : VimTestCase() {
|
||||
@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
fun `test status string in normal`() {
|
||||
configureByText("123")
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("", statusString)
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in insert`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("INSERT", statusString)
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in replace`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("R"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("REPLACE", statusString)
|
||||
}
|
||||
|
||||
@ -52,7 +53,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in visual`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("v"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- VISUAL --", statusString)
|
||||
}
|
||||
|
||||
@ -60,7 +61,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in visual line`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("V"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- VISUAL LINE --", statusString)
|
||||
}
|
||||
|
||||
@ -68,7 +69,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in visual block`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("<C-V>"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- VISUAL BLOCK --", statusString)
|
||||
}
|
||||
|
||||
@ -76,7 +77,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in select`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("gh"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- SELECT --", statusString)
|
||||
}
|
||||
|
||||
@ -84,7 +85,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in select line`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("gH"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- SELECT LINE --", statusString)
|
||||
}
|
||||
|
||||
@ -92,7 +93,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in select block`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("g<C-H>"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- SELECT BLOCK --", statusString)
|
||||
}
|
||||
|
||||
@ -100,7 +101,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O>"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) --", statusString)
|
||||
}
|
||||
|
||||
@ -108,7 +109,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command visual`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O>v"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) VISUAL --", statusString)
|
||||
}
|
||||
|
||||
@ -116,7 +117,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command visual block`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O><C-V>"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) VISUAL BLOCK --", statusString)
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command visual line`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O>V"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) VISUAL LINE --", statusString)
|
||||
}
|
||||
|
||||
@ -132,7 +133,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command select`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O>gh"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) SELECT --", statusString)
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command select block`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O>g<C-H>"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) SELECT BLOCK --", statusString)
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ class CommandStateTest : VimTestCase() {
|
||||
fun `test status string in one command select line`() {
|
||||
configureByText("123")
|
||||
typeText(parseKeys("i<C-O>gH"))
|
||||
val statusString = myFixture.editor.commandState.getStatusString()
|
||||
val statusString = myFixture.editor.vim.commandState.getStatusString()
|
||||
assertEquals("-- (insert) SELECT LINE --", statusString)
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
|
||||
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.plugins.ideavim.SkipNeovimReason
|
||||
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
|
||||
import org.jetbrains.plugins.ideavim.VimTestCase
|
||||
@ -274,7 +275,7 @@ class VimMultipleCursorsExtensionTest : VimTestCase() {
|
||||
|dfkjsg
|
||||
""".trimMargin()
|
||||
val editor = configureByText(before)
|
||||
editor.commandState.pushModes(CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
editor.vim.commandState.pushModes(CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
|
||||
typeText(parseKeys("<A-p>"))
|
||||
|
||||
@ -483,7 +484,7 @@ class VimMultipleCursorsExtensionTest : VimTestCase() {
|
||||
|dfkjsg
|
||||
""".trimMargin()
|
||||
val editor = configureByText(before)
|
||||
editor.commandState.pushModes(CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
editor.vim.commandState.pushModes(CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
|
||||
typeText(parseKeys("<A-x>"))
|
||||
assertMode(CommandState.Mode.VISUAL)
|
||||
@ -571,7 +572,7 @@ 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)
|
||||
editor.commandState.pushModes(CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
editor.vim.commandState.pushModes(CommandState.Mode.VISUAL, CommandState.SubMode.VISUAL_CHARACTER)
|
||||
|
||||
typeText(parseKeys("<A-n><A-n>"))
|
||||
val after = "test ${s}t.*st$se toast tallest ${s}t.*st$se"
|
||||
|
@ -21,9 +21,10 @@ package org.jetbrains.plugins.ideavim.propertybased
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.helper.StringHelper
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.key.CommandNode
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
import org.jetbrains.jetCheck.Generator
|
||||
import org.jetbrains.jetCheck.ImperativeCommand
|
||||
import org.jetbrains.jetCheck.PropertyChecker
|
||||
@ -93,7 +94,7 @@ class RandomActionsPropertyTest : VimPropertyTest() {
|
||||
|
||||
private class AvailableActions(private val editor: Editor) : ImperativeCommand {
|
||||
override fun performCommand(env: ImperativeCommand.Environment) {
|
||||
val currentNode = CommandState.getInstance(editor).commandBuilder.getCurrentTrie()
|
||||
val currentNode = editor.vim.commandState.commandBuilder.getCurrentTrie()
|
||||
|
||||
val possibleKeys = currentNode.keys.toList().sortedBy { StringHelper.toKeyNotation(it) }
|
||||
val keyGenerator = Generator.integers(0, possibleKeys.lastIndex)
|
||||
|
@ -21,7 +21,6 @@ package org.jetbrains.plugins.ideavim.propertybased
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.KeyHandler
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.command.CommandState
|
||||
import com.maddyhome.idea.vim.group.MotionGroup
|
||||
import com.maddyhome.idea.vim.helper.commandState
|
||||
import com.maddyhome.idea.vim.newapi.vim
|
||||
@ -36,14 +35,14 @@ abstract class VimPropertyTest : VimTestCase() {
|
||||
}
|
||||
|
||||
protected fun reset(editor: Editor) {
|
||||
editor.commandState.mappingState.resetMappingSequence()
|
||||
editor.vim.commandState.mappingState.resetMappingSequence()
|
||||
VimPlugin.getKey().resetKeyMappings()
|
||||
|
||||
KeyHandler.getInstance().fullReset(editor.vim)
|
||||
VimPlugin.getRegister().resetRegisters()
|
||||
editor.caretModel.runForEachCaret { it.moveToOffset(0) }
|
||||
|
||||
CommandState.getInstance(editor).resetDigraph()
|
||||
editor.vim.commandState.resetDigraph()
|
||||
VimPlugin.getSearch().resetState()
|
||||
VimPlugin.getChange().reset()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user