diff --git a/src/main/java/com/maddyhome/idea/vim/VimPlugin.java b/src/main/java/com/maddyhome/idea/vim/VimPlugin.java index a8482a189..101803c0a 100644 --- a/src/main/java/com/maddyhome/idea/vim/VimPlugin.java +++ b/src/main/java/com/maddyhome/idea/vim/VimPlugin.java @@ -38,7 +38,6 @@ import com.maddyhome.idea.vim.helper.MacKeyRepeat; import com.maddyhome.idea.vim.listener.VimListenerManager; import com.maddyhome.idea.vim.newapi.IjVimInjector; import com.maddyhome.idea.vim.ui.StatusBarIconFactory; -import com.maddyhome.idea.vim.ui.ex.ExEntryPanel; import com.maddyhome.idea.vim.vimscript.services.VariableService; import com.maddyhome.idea.vim.yank.YankGroupBase; import org.jdom.Element; @@ -46,6 +45,7 @@ import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static com.maddyhome.idea.vim.api.VimInjectorKt.injector; import static com.maddyhome.idea.vim.group.EditorGroup.EDITOR_STORE_ELEMENT; import static com.maddyhome.idea.vim.group.KeyGroup.SHORTCUT_CONFLICTS_ELEMENT; import static com.maddyhome.idea.vim.vimscript.services.VimRcService.executeIdeaVimRc; @@ -283,11 +283,11 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable if (!ApplicationManager.getApplication().isUnitTestMode()) { try { - VimInjectorKt.injector.getOptionGroup().startInitVimRc(); + injector.getOptionGroup().startInitVimRc(); executeIdeaVimRc(editor); } finally { - VimInjectorKt.injector.getOptionGroup().endInitVimRc(); + injector.getOptionGroup().endInitVimRc(); } } } @@ -352,7 +352,7 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable if (unsubscribe) { VimListenerManager.INSTANCE.turnOff(); } - ExEntryPanel.fullReset(); + injector.getCommandLine().fullReset(); // Unregister vim actions in command mode RegisterActions.unregisterActions(); diff --git a/src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt b/src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt index 54f1ac020..f24819540 100644 --- a/src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt +++ b/src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt @@ -21,16 +21,15 @@ import com.intellij.util.text.CharSequenceReader import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance import com.maddyhome.idea.vim.KeyProcessResult import com.maddyhome.idea.vim.VimPlugin -import com.maddyhome.idea.vim.api.ExecutionContext import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.VimProcessGroupBase import com.maddyhome.idea.vim.api.globalOptions import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.command.Command import com.maddyhome.idea.vim.helper.requestFocus -import com.maddyhome.idea.vim.helper.vimStateMachine import com.maddyhome.idea.vim.newapi.ij import com.maddyhome.idea.vim.state.mode.Mode +import com.maddyhome.idea.vim.state.mode.Mode.NORMAL import com.maddyhome.idea.vim.state.mode.ReturnableFromCmd import com.maddyhome.idea.vim.state.mode.inVisualMode import com.maddyhome.idea.vim.state.mode.returnTo @@ -89,10 +88,10 @@ public class ProcessGroup : VimProcessGroupBase() { // This will only get called if somehow the key focus ended up in the editor while the ex entry window // is open. So I'll put focus back in the editor and process the key. - val panel = ExEntryPanel.getInstance() - if (panel.isActive) { + val panel = injector.commandLine.getActiveCommandLine() + if (panel != null) { processResultBuilder.addExecutionStep { _, _, _ -> - requestFocus(panel.entry) + requestFocus((panel as ExEntryPanel).entry) panel.handleKey(stroke) } return true diff --git a/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanelService.kt b/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanelService.kt index 26d94a28d..6abfb4c5d 100644 --- a/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanelService.kt +++ b/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanelService.kt @@ -25,7 +25,8 @@ import javax.swing.KeyStroke public class ExEntryPanelService : VimCommandLineService { public override fun getActiveCommandLine(): VimCommandLine? { - return ExEntryPanel.instance + val instance = ExEntryPanel.instance ?: return null + return if (instance.isActive) instance else null } override fun inputString(vimEditor: VimEditor, context: ExecutionContext, prompt: String, finishOn: Char?): String? { @@ -93,4 +94,8 @@ public class ExEntryPanelService : VimCommandLineService { panel.activate(editor.ij, context.ij, label, initText, count) return panel } + + override fun fullReset() { + ExEntryPanel.fullReset() + } } diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/ex/ProcessExEntryActions.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/ex/ProcessExEntryActions.kt index 2593ce32b..04efb9860 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/ex/ProcessExEntryActions.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/action/ex/ProcessExEntryActions.kt @@ -60,8 +60,8 @@ public class ProcessExCommandEntryAction : MotionActionHandler.SingleExecution() override val motionType: MotionType = MotionType.LINE_WISE override fun getOffset(editor: VimEditor, context: ExecutionContext, argument: Argument?, operatorArguments: OperatorArguments): Motion { - val panel = injector.commandLine.getActiveCommandLine()!! - panel.deactivate(true) + if (argument == null) return Motion.Error + try { // Exit Command-line mode and return to the previous mode before executing the command (this is set to Normal in // startExEntry). Remember from startExEntry that we might still have selection and/or multiple carets, even @@ -71,7 +71,7 @@ public class ProcessExCommandEntryAction : MotionActionHandler.SingleExecution() logger.debug("processing command") - val text = panel.text + val text = argument.string val shouldSkipHistory = getInstance(editor).mappingState.isExecutingMap() || injector.macro.isExecutingMacro injector.vimscriptExecutor.execute(text, editor, context, shouldSkipHistory, true, CommandLineVimLContext) } catch (e: ExException) { diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLineService.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLineService.kt index 0b1509d3b..ae84a8e7f 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLineService.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLineService.kt @@ -23,4 +23,6 @@ public interface VimCommandLineService { * @param count TODO */ public fun create(editor: VimEditor, context: ExecutionContext, label: String, initText: String, count: Int): VimCommandLine + + public fun fullReset() } \ No newline at end of file diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimProcessGroupBase.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimProcessGroupBase.kt index 39438a25e..d72eec6a0 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimProcessGroupBase.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimProcessGroupBase.kt @@ -8,4 +8,14 @@ package com.maddyhome.idea.vim.api -public abstract class VimProcessGroupBase : VimProcessGroup +import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance +import com.maddyhome.idea.vim.state.mode.Mode.NORMAL + +public abstract class VimProcessGroupBase : VimProcessGroup { + public override fun cancelExEntry(editor: VimEditor, resetCaret: Boolean) { + editor.mode = NORMAL() + injector.commandLine.getActiveCommandLine()?.deactivate(true, resetCaret) + getInstance().keyHandlerState.leaveCommandLine() + getInstance().reset(editor) + } +}