1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-19 21:39:56 +02:00

Changes to replace ExEntryPanel with interface and move more code to engine

This commit is contained in:
Filipp Vakhitov 2024-05-29 16:25:54 +03:00 committed by Alex Pláte
parent d00bd8bb25
commit f5cd2c173f
6 changed files with 30 additions and 14 deletions
src/main/java/com/maddyhome/idea/vim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim

View File

@ -38,7 +38,6 @@ import com.maddyhome.idea.vim.helper.MacKeyRepeat;
import com.maddyhome.idea.vim.listener.VimListenerManager; import com.maddyhome.idea.vim.listener.VimListenerManager;
import com.maddyhome.idea.vim.newapi.IjVimInjector; import com.maddyhome.idea.vim.newapi.IjVimInjector;
import com.maddyhome.idea.vim.ui.StatusBarIconFactory; 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.vimscript.services.VariableService;
import com.maddyhome.idea.vim.yank.YankGroupBase; import com.maddyhome.idea.vim.yank.YankGroupBase;
import org.jdom.Element; import org.jdom.Element;
@ -46,6 +45,7 @@ import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.EditorGroup.EDITOR_STORE_ELEMENT;
import static com.maddyhome.idea.vim.group.KeyGroup.SHORTCUT_CONFLICTS_ELEMENT; import static com.maddyhome.idea.vim.group.KeyGroup.SHORTCUT_CONFLICTS_ELEMENT;
import static com.maddyhome.idea.vim.vimscript.services.VimRcService.executeIdeaVimRc; 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()) { if (!ApplicationManager.getApplication().isUnitTestMode()) {
try { try {
VimInjectorKt.injector.getOptionGroup().startInitVimRc(); injector.getOptionGroup().startInitVimRc();
executeIdeaVimRc(editor); executeIdeaVimRc(editor);
} }
finally { finally {
VimInjectorKt.injector.getOptionGroup().endInitVimRc(); injector.getOptionGroup().endInitVimRc();
} }
} }
} }
@ -352,7 +352,7 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
if (unsubscribe) { if (unsubscribe) {
VimListenerManager.INSTANCE.turnOff(); VimListenerManager.INSTANCE.turnOff();
} }
ExEntryPanel.fullReset(); injector.getCommandLine().fullReset();
// Unregister vim actions in command mode // Unregister vim actions in command mode
RegisterActions.unregisterActions(); RegisterActions.unregisterActions();

View File

@ -21,16 +21,15 @@ import com.intellij.util.text.CharSequenceReader
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
import com.maddyhome.idea.vim.KeyProcessResult import com.maddyhome.idea.vim.KeyProcessResult
import com.maddyhome.idea.vim.VimPlugin 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.VimEditor
import com.maddyhome.idea.vim.api.VimProcessGroupBase import com.maddyhome.idea.vim.api.VimProcessGroupBase
import com.maddyhome.idea.vim.api.globalOptions import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.Command import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.helper.requestFocus 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.newapi.ij
import com.maddyhome.idea.vim.state.mode.Mode 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.ReturnableFromCmd
import com.maddyhome.idea.vim.state.mode.inVisualMode import com.maddyhome.idea.vim.state.mode.inVisualMode
import com.maddyhome.idea.vim.state.mode.returnTo 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 // 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. // is open. So I'll put focus back in the editor and process the key.
val panel = ExEntryPanel.getInstance() val panel = injector.commandLine.getActiveCommandLine()
if (panel.isActive) { if (panel != null) {
processResultBuilder.addExecutionStep { _, _, _ -> processResultBuilder.addExecutionStep { _, _, _ ->
requestFocus(panel.entry) requestFocus((panel as ExEntryPanel).entry)
panel.handleKey(stroke) panel.handleKey(stroke)
} }
return true return true

View File

@ -25,7 +25,8 @@ import javax.swing.KeyStroke
public class ExEntryPanelService : VimCommandLineService { public class ExEntryPanelService : VimCommandLineService {
public override fun getActiveCommandLine(): VimCommandLine? { 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? { 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) panel.activate(editor.ij, context.ij, label, initText, count)
return panel return panel
} }
override fun fullReset() {
ExEntryPanel.fullReset()
}
} }

View File

@ -60,8 +60,8 @@ public class ProcessExCommandEntryAction : MotionActionHandler.SingleExecution()
override val motionType: MotionType = MotionType.LINE_WISE override val motionType: MotionType = MotionType.LINE_WISE
override fun getOffset(editor: VimEditor, context: ExecutionContext, argument: Argument?, operatorArguments: OperatorArguments): Motion { override fun getOffset(editor: VimEditor, context: ExecutionContext, argument: Argument?, operatorArguments: OperatorArguments): Motion {
val panel = injector.commandLine.getActiveCommandLine()!! if (argument == null) return Motion.Error
panel.deactivate(true)
try { try {
// Exit Command-line mode and return to the previous mode before executing the command (this is set to Normal in // 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 // 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") logger.debug("processing command")
val text = panel.text val text = argument.string
val shouldSkipHistory = getInstance(editor).mappingState.isExecutingMap() || injector.macro.isExecutingMacro val shouldSkipHistory = getInstance(editor).mappingState.isExecutingMap() || injector.macro.isExecutingMacro
injector.vimscriptExecutor.execute(text, editor, context, shouldSkipHistory, true, CommandLineVimLContext) injector.vimscriptExecutor.execute(text, editor, context, shouldSkipHistory, true, CommandLineVimLContext)
} catch (e: ExException) { } catch (e: ExException) {

View File

@ -23,4 +23,6 @@ public interface VimCommandLineService {
* @param count TODO * @param count TODO
*/ */
public fun create(editor: VimEditor, context: ExecutionContext, label: String, initText: String, count: Int): VimCommandLine public fun create(editor: VimEditor, context: ExecutionContext, label: String, initText: String, count: Int): VimCommandLine
public fun fullReset()
} }

View File

@ -8,4 +8,14 @@
package com.maddyhome.idea.vim.api 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)
}
}