Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fleet #942

Merged
merged 40 commits into from
Jul 17, 2024
Merged

Fleet #942

Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
34769dc
Add KeyHandling logic to VimOutputPanel
lippfi Jul 8, 2024
f1626ed
Add label field to VimOutputPanel
lippfi Jul 8, 2024
2bde0c5
Fix passing key to editor when the output panel is scrolled to its end
lippfi Jul 8, 2024
aaf9755
Introduce ModalInput to get rid of Swing's secondary loop
lippfi Jul 9, 2024
686a8ed
Fix tests
lippfi Jul 9, 2024
f0cbb84
Add typeText() method to VimModalInput
lippfi Jul 9, 2024
820411c
Rename argument
lippfi Jul 9, 2024
fe5d2a6
Delegate handling closing keystrokes to implementations
lippfi Jul 9, 2024
98b62e4
Create a Wrapper for ExEntryPanel
lippfi Jul 9, 2024
66bb7f1
Always register shortcuts
lippfi Jul 9, 2024
c8cd390
Replace deprecated inputString() with ModalInput
lippfi Jul 9, 2024
198db5e
Remove unnecessary write action
lippfi Jul 9, 2024
93a98a6
Replace cancelExEntry with close method in VimCommandLine
lippfi Jul 10, 2024
e28083d
Add readInputAndProcess to replace inputString and save us from using…
lippfi Jul 10, 2024
e1bda4d
Add support for finishOn in readInputAndProcess
lippfi Jul 10, 2024
b2f706f
Fix VisualAreaMatcher
lippfi Jul 10, 2024
a1c9649
Remove unused fields from VimProcessGroup
lippfi Jul 10, 2024
81afa16
Move lastCommand to CmdFilterCommand
lippfi Jul 10, 2024
e358a38
Remove startExEntry method
lippfi Jul 10, 2024
5cbb621
Move command line key handling logic to KeyConsumer
lippfi Jul 10, 2024
1a02a22
Remove shouldRecord from KeyConsumer
lippfi Jul 10, 2024
ce687f6
ProcessSubstituteCommand refactoring part 1
lippfi Jul 11, 2024
b254926
ProcessSubstituteCommand refactoring part 2
lippfi Jul 11, 2024
d8ffee1
ProcessSubstituteCommand refactoring part 3
lippfi Jul 11, 2024
4803b03
ProcessSubstituteCommand refactoring part 4
lippfi Jul 11, 2024
6289246
ProcessSubstituteCommand refactoring part 5
lippfi Jul 11, 2024
ab19ed6
ProcessSubstituteCommand refactoring part 6
lippfi Jul 11, 2024
4d92904
ProcessSubstituteCommand refactoring part 7
lippfi Jul 11, 2024
a5e4666
ProcessSubstituteCommand refactoring part 8
lippfi Jul 11, 2024
f6fd7fe
ProcessSubstituteCommand refactoring part 9
lippfi Jul 11, 2024
789f2f2
Remove confirmChoice method
lippfi Jul 11, 2024
9f965b8
Remove modal input on click
lippfi Jul 11, 2024
d111474
Remove typing in ModalInput
lippfi Jul 11, 2024
b2a24d3
Remove isCancel argument
lippfi Jul 11, 2024
91ab7a0
Add comment
lippfi Jul 11, 2024
1e1be95
Fix compilation
lippfi Jul 11, 2024
385bd23
Fix surround
lippfi Jul 12, 2024
38e71f1
Remove deprecated method from vim-engine
lippfi Jul 12, 2024
7028587
Safer getCurrentModalInput()
lippfi Jul 12, 2024
bb47284
Make myInputInterceptor private
lippfi Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/VimProjectService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
internal class VimProjectService(val project: Project) : Disposable {
override fun dispose() {
// Not sure if this is a best solution
ExEntryPanel.getInstance().editor = null
ExEntryPanel.getInstance().setEditor(null)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
private fun getEditor(e: AnActionEvent): Editor? {
return e.getData(PlatformDataKeys.EDITOR)
?: if (e.getData(PlatformDataKeys.CONTEXT_COMPONENT) is ExTextField) {
ExEntryPanel.getInstance().editor
ExEntryPanel.getInstance().ijEditor
} else {
null
}
Expand Down
53 changes: 51 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/ex/ExOutputModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ package com.maddyhome.idea.vim.ex

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.api.VimOutputPanel
import com.maddyhome.idea.vim.api.VimOutputPanelBase
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.helper.vimExOutput
import com.maddyhome.idea.vim.ui.ExOutputPanel
import java.lang.ref.WeakReference
import javax.swing.KeyStroke

// TODO: We need a nicer way to handle output, especially wrt testing, appending + clearing
class ExOutputModel(private val myEditor: WeakReference<Editor>) : VimOutputPanel {
class ExOutputModel(private val myEditor: WeakReference<Editor>) : VimOutputPanelBase() {
private var isActiveInTestMode = false

val editor get() = myEditor.get()
Expand Down Expand Up @@ -48,6 +49,24 @@ class ExOutputModel(private val myEditor: WeakReference<Editor>) : VimOutputPane
}
}

override fun scrollPage() {
val notNullEditor = editor ?: return
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return
panel.scrollPage()
}

override fun scrollHalfPage() {
val notNullEditor = editor ?: return
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return
panel.scrollHalfPage()
}

override fun scrollLine() {
val notNullEditor = editor ?: return
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return
panel.scrollLine()
}

override var text: String = ""
get() = if (!ApplicationManager.getApplication().isUnitTestMode) {
editor?.let { ExOutputPanel.getInstance(it).text } ?: ""
Expand All @@ -66,6 +85,17 @@ class ExOutputModel(private val myEditor: WeakReference<Editor>) : VimOutputPane
isActiveInTestMode = newValue.isNotEmpty()
}
}
override var label: String
get() {
val notNullEditor = editor ?: return ""
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return ""
return panel.myLabel.text
}
set(value) {
val notNullEditor = editor ?: return
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return
panel.myLabel.text = value
}

fun output(text: String) {
this.text = text
Expand All @@ -75,6 +105,25 @@ class ExOutputModel(private val myEditor: WeakReference<Editor>) : VimOutputPane
text = ""
}

override val atEnd: Boolean
get() {
val notNullEditor = editor ?: return false
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return false
return panel.isAtEnd()
}

override fun onBadKey() {
val notNullEditor = editor ?: return
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return
panel.onBadKey()
}

override fun close(key: KeyStroke?) {
val notNullEditor = editor ?: return
val panel = ExOutputPanel.getNullablePanel(notNullEditor) ?: return
panel.close(key)
}

override fun close() {
if (!ApplicationManager.getApplication().isUnitTestMode) {
editor?.let { ExOutputPanel.getInstance(it).close() }
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/group/EditorGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,16 @@ public void propertyChange(PropertyChangeEvent evt) {
// Note that IDE scale is handled by LafManager.lookAndFeelChanged
VimCommandLine activeCommandLine = injector.getCommandLine().getActiveCommandLine();
if (activeCommandLine != null) {
injector.getProcessGroup().cancelExEntry(new IjVimEditor(editor), true, false);
activeCommandLine.close(true, false);
}
ExOutputModel exOutputModel = ExOutputModel.tryGetInstance(editor);
if (exOutputModel != null) {
exOutputModel.close();
}
VimModalInput modalInput = injector.getModalInput().getCurrentModalInput();
if (modalInput != null) {
modalInput.deactivate(true, false);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/group/MotionGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ internal class MotionGroup : VimMotionGroupBase() {
KeyHandler.getInstance().reset(vimEditor)
}
is Mode.CMD_LINE -> {
injector.processGroup.cancelExEntry(vimEditor, refocusOwningEditor = false, resetCaret = false)
val commandLine = injector.commandLine.getActiveCommandLine() ?: return
commandLine.close(refocusOwningEditor = false, resetCaret = false)
ExOutputModel.tryGetInstance(editor)?.close()
}
else -> {}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/group/ProcessGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class ProcessGroup : VimProcessGroupBase() {
val progressIndicator = ProgressIndicatorProvider.getInstance().progressIndicator
val output = handler.runProcessWithProgressIndicator(progressIndicator)

lastCommand = command

if (output.isCancelled) {
// TODO: Vim will use whatever text has already been written to stdout
// For whatever reason, we're not getting any here, so just throw an exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import com.maddyhome.idea.vim.newapi.ij
*/
class IJEditorFocusListener : EditorListener {
override fun focusGained(editor: VimEditor) {
val editorInFocus = KeyHandler.getInstance().editorInFocus
if (editorInFocus != null && editorInFocus.ij == editor.ij) return

KeyHandler.getInstance().editorInFocus = editor

// We add Vim bindings to all opened editors, including editors used as UI controls rather than just project file
// editors. This includes editors used as part of the UI, such as the VCS commit message, or used as read-only
// viewers for text output, such as log files in run configurations or the Git Console tab. And editors are used for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,8 @@ internal object VimListenerManager {

if (event.area == EditorMouseEventArea.EDITING_AREA) {
val editor = event.editor
val commandLine = injector.commandLine.getActiveCommandLine()
if (commandLine != null) {
injector.processGroup.cancelExEntry(editor.vim, refocusOwningEditor = true, resetCaret = false)
}
injector.commandLine.getActiveCommandLine()?.close(refocusOwningEditor = true, resetCaret = false)
injector.modalInput.getCurrentModalInput()?.deactivate(refocusOwningEditor = true, resetCaret = false)

ExOutputModel.tryGetInstance(editor)?.close()

Expand Down Expand Up @@ -766,10 +764,8 @@ internal object VimListenerManager {
event.area != EditorMouseEventArea.FOLDING_OUTLINE_AREA &&
event.mouseEvent.button != MouseEvent.BUTTON3
) {
val commandLine = injector.commandLine.getActiveCommandLine()
if (commandLine != null) {
injector.processGroup.cancelExEntry(event.editor.vim, refocusOwningEditor = true, resetCaret = false)
}
injector.commandLine.getActiveCommandLine()?.close(refocusOwningEditor = true, resetCaret = false)
injector.modalInput.getCurrentModalInput()?.deactivate(refocusOwningEditor = true, resetCaret = false)

ExOutputModel.getInstance(event.editor).close()
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/newapi/IjVimInjector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.maddyhome.idea.vim.api.VimApplication
import com.maddyhome.idea.vim.api.VimChangeGroup
import com.maddyhome.idea.vim.api.VimClipboardManager
import com.maddyhome.idea.vim.api.VimCommandGroup
import com.maddyhome.idea.vim.api.VimCommandLine
import com.maddyhome.idea.vim.api.VimCommandLineService
import com.maddyhome.idea.vim.api.VimDigraphGroup
import com.maddyhome.idea.vim.api.VimEditor
Expand All @@ -36,6 +37,7 @@ import com.maddyhome.idea.vim.api.VimKeyGroup
import com.maddyhome.idea.vim.api.VimLookupManager
import com.maddyhome.idea.vim.api.VimMarkService
import com.maddyhome.idea.vim.api.VimMessages
import com.maddyhome.idea.vim.api.VimModalInputService
import com.maddyhome.idea.vim.api.VimMotionGroup
import com.maddyhome.idea.vim.api.VimOptionGroup
import com.maddyhome.idea.vim.api.VimOutputPanelService
Expand Down Expand Up @@ -83,6 +85,7 @@ import com.maddyhome.idea.vim.put.VimPut
import com.maddyhome.idea.vim.register.VimRegisterGroup
import com.maddyhome.idea.vim.state.VimStateMachine
import com.maddyhome.idea.vim.ui.VimRcFileState
import com.maddyhome.idea.vim.ui.ex.ExEntryPanelService
import com.maddyhome.idea.vim.undo.VimUndoRedo
import com.maddyhome.idea.vim.vimscript.Executor
import com.maddyhome.idea.vim.vimscript.services.VariableService
Expand Down Expand Up @@ -183,6 +186,8 @@ internal class IjVimInjector : VimInjectorBase() {
get() = com.maddyhome.idea.vim.vimscript.parser.VimscriptParser
override val commandLine: VimCommandLineService
get() = service()
override val modalInput: VimModalInputService
get() = commandLine as ExEntryPanelService
override val outputPanel: VimOutputPanelService
get() = service()

Expand Down
53 changes: 0 additions & 53 deletions src/main/java/com/maddyhome/idea/vim/newapi/IjVimSearchGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,59 +97,6 @@ open class IjVimSearchGroup : VimSearchGroupBase(), PersistentStateComponent<Ele
updateSearchHighlights(getLastUsedPattern(), lastIgnoreSmartCase, showSearchHighlight, true)
}

override fun confirmChoice(
editor: VimEditor,
context: ExecutionContext,
match: String,
caret: VimCaret,
startOffset: Int,
): ReplaceConfirmationChoice {
val result: Ref<ReplaceConfirmationChoice> = Ref.create(ReplaceConfirmationChoice.QUIT)
val keyStrokeProcessor: Function1<KeyStroke, Boolean> = label@{ key: KeyStroke ->
val choice: ReplaceConfirmationChoice
val c = key.keyChar
choice = if (key.isCloseKeyStroke() || c == 'q') {
ReplaceConfirmationChoice.QUIT
} else if (c == 'y') {
ReplaceConfirmationChoice.SUBSTITUTE_THIS
} else if (c == 'l') {
ReplaceConfirmationChoice.SUBSTITUTE_LAST
} else if (c == 'n') {
ReplaceConfirmationChoice.SKIP
} else if (c == 'a') {
ReplaceConfirmationChoice.SUBSTITUTE_ALL
} else {
return@label true
}
// TODO: Handle <C-E> and <C-Y>
result.set(choice)
false
}
if (ApplicationManager.getApplication().isUnitTestMode) {
caret.moveToOffset(startOffset)
val inputModel = getInstance(editor.ij)
var key = inputModel.nextKeyStroke()
while (key != null) {
if (!keyStrokeProcessor.invoke(key)) {
break
}
key = inputModel.nextKeyStroke()
}
} else {
// XXX: The Ex entry panel is used only for UI here, its logic might be inappropriate for this method
val exEntryPanel = injector.commandLine.createWithoutShortcuts(
editor,
context,
MessageHelper.message("replace.with.0", match),
"",
)
caret.moveToOffset(startOffset)
ModalEntry.activate(editor, keyStrokeProcessor)
exEntryPanel.deactivate(refocusOwningEditor = true, resetCaret = false)
}
return result.get()
}

override fun addSubstitutionConfirmationHighlight(
editor: VimEditor,
startOffset: Int,
Expand Down
Loading
Loading