From e8afc0dece30520a69f0f36eabdbb5e4ae84039f Mon Sep 17 00:00:00 2001 From: Filipp Vakhitov Date: Mon, 3 Jun 2024 10:05:21 +0300 Subject: [PATCH] Move one method to VimProcessGroupBase --- .../maddyhome/idea/vim/group/ProcessGroup.kt | 25 ------------------- .../idea/vim/ui/ex/ExEntryPanel.java | 6 +++++ .../maddyhome/idea/vim/api/VimCommandLine.kt | 3 +++ .../idea/vim/api/VimProcessGroupBase.kt | 24 ++++++++++++++++++ 4 files changed, 33 insertions(+), 25 deletions(-) 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 73655b59ee5..c3590b16f49 100644 --- a/src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt +++ b/src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt @@ -18,24 +18,18 @@ import com.intellij.openapi.progress.ProgressIndicatorProvider import com.intellij.openapi.progress.ProgressManager import com.intellij.util.execution.ParametersListUtil 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.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.helper.requestFocus 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.ui.ex.ExEntryPanel import java.io.BufferedWriter import java.io.IOException import java.io.OutputStreamWriter import java.io.Reader import java.io.Writer -import javax.swing.KeyStroke public class ProcessGroup : VimProcessGroupBase() { override var lastCommand: String? = null @@ -43,25 +37,6 @@ public class ProcessGroup : VimProcessGroupBase() { override var isCommandProcessing: Boolean = false override var modeBeforeCommandProcessing: Mode? = null - public override fun processExKey(editor: VimEditor, stroke: KeyStroke, processResultBuilder: KeyProcessResult.KeyProcessResultBuilder): Boolean { - // 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 = injector.commandLine.getActiveCommandLine() - if (panel != null) { - processResultBuilder.addExecutionStep { _, _, _ -> - requestFocus((panel as ExEntryPanel).entry) - panel.handleKey(stroke) - } - return true - } else { - processResultBuilder.addExecutionStep { _, lambdaEditor, _ -> - lambdaEditor.mode = NORMAL() - getInstance().reset(lambdaEditor) - } - return false - } - } @Throws(ExecutionException::class, ProcessCanceledException::class) public override fun executeCommand( diff --git a/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java b/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java index 8988c9c5e43..acd4ff6c646 100644 --- a/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java +++ b/src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java @@ -16,6 +16,7 @@ import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollingModel; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.DocumentAdapter; import com.intellij.util.IJSwingUtilities; import com.maddyhome.idea.vim.EventFacade; @@ -522,6 +523,11 @@ public boolean isReplaceMode() { return isReplaceMode; } + @Override + public void focus() { + IdeFocusManager.findInstance().requestFocus(this, true); + } + public static class LafListener implements LafManagerListener { @Override public void lookAndFeelChanged(@NotNull LafManager source) { diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt index bc48e361863..f176066605c 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCommandLine.kt @@ -77,4 +77,7 @@ public interface VimCommandLine { public fun clearCurrentAction() public fun deactivate(refocusOwningEditor: Boolean, resetCaret: Boolean) + + // FIXME I don't want it to conflict with Swings `requestFocus` and can suggest a better name + public fun focus() } \ 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 1f9917ae143..a449344226a 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 @@ -9,9 +9,33 @@ package com.maddyhome.idea.vim.api import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance +import com.maddyhome.idea.vim.KeyProcessResult import com.maddyhome.idea.vim.state.mode.Mode.NORMAL +import javax.swing.KeyStroke public abstract class VimProcessGroupBase : VimProcessGroup { + public override fun processExKey(editor: VimEditor, stroke: KeyStroke, processResultBuilder: KeyProcessResult.KeyProcessResultBuilder): Boolean { + // 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. + // FIXME comment above is not true. This method is called all the time. Is there a way to make it work like in the comment above? + // TODO maybe something like `Propagate.CONTINUE` will help + + val panel = injector.commandLine.getActiveCommandLine() + if (panel != null) { + processResultBuilder.addExecutionStep { _, _, _ -> + panel.focus() + panel.handleKey(stroke) + } + return true + } else { + processResultBuilder.addExecutionStep { _, lambdaEditor, _ -> + lambdaEditor.mode = NORMAL() + getInstance().reset(lambdaEditor) + } + return false + } + } + public override fun cancelExEntry(editor: VimEditor, resetCaret: Boolean) { editor.mode = NORMAL() injector.commandLine.getActiveCommandLine()?.deactivate(refocusOwningEditor = true, resetCaret)