Skip to content

Commit

Permalink
Move one method to VimProcessGroupBase
Browse files Browse the repository at this point in the history
  • Loading branch information
lippfi committed Jun 3, 2024
1 parent f02d12d commit e8afc0d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,25 @@ 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
private set
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(
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/ui/ex/ExEntryPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e8afc0d

Please sign in to comment.