mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-02-23 23:46:03 +01:00
Fix possible bug in the ExOutputModel.show()
method and add documentation
This commit is contained in:
parent
16455f7241
commit
9bb9cb13e3
src/main/java/com/maddyhome/idea/vim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api
@ -10,6 +10,7 @@ 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.injector
|
||||
import com.maddyhome.idea.vim.helper.vimExOutput
|
||||
import com.maddyhome.idea.vim.ui.ExOutputPanel
|
||||
|
||||
@ -17,7 +18,7 @@ import com.maddyhome.idea.vim.ui.ExOutputPanel
|
||||
class ExOutputModel(private val myEditor: Editor) : VimOutputPanel {
|
||||
private var isActiveInTestMode = false
|
||||
|
||||
override val isShown: Boolean
|
||||
val isActive: Boolean
|
||||
get() = if (!ApplicationManager.getApplication().isUnitTestMode) {
|
||||
ExOutputPanel.getNullablePanel(myEditor)?.myActive ?: false
|
||||
} else {
|
||||
@ -29,6 +30,9 @@ class ExOutputModel(private val myEditor: Editor) : VimOutputPanel {
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
val currentPanel = injector.outputPanel.getCurrentOutputPanel()
|
||||
if (currentPanel != null && currentPanel != this) currentPanel.close()
|
||||
|
||||
myEditor.vimExOutput = this
|
||||
val exOutputPanel = ExOutputPanel.getInstance(myEditor)
|
||||
if (!exOutputPanel.myActive) {
|
||||
|
@ -19,7 +19,7 @@ class IjOutputPanelService : VimOutputPanelServiceBase() {
|
||||
private var activeOutputPanel: VimOutputPanel? = null
|
||||
|
||||
override fun getCurrentOutputPanel(): VimOutputPanel? {
|
||||
return activeOutputPanel?.takeIf { it.isShown }
|
||||
return activeOutputPanel?.takeIf { (it as ExOutputModel).isActive }
|
||||
}
|
||||
|
||||
override fun create(editor: VimEditor, context: ExecutionContext): VimOutputPanel {
|
||||
|
@ -9,15 +9,31 @@
|
||||
package com.maddyhome.idea.vim.api
|
||||
|
||||
interface VimOutputPanel {
|
||||
/**
|
||||
* The current text displayed in the output panel.
|
||||
* The actual text may be different (if we called the [addText] method and did not call [show] afterward)
|
||||
*/
|
||||
val text: String
|
||||
val isShown: Boolean
|
||||
|
||||
/**
|
||||
* Appends the specified text to the existing content of the output panel.
|
||||
* If 'isNewLine' is true, the text will begin on a new line.
|
||||
*
|
||||
* Note: The full text content is not updated in the display until [show] is invoked.
|
||||
*
|
||||
* @param text The text to append.
|
||||
* @param isNewLine Whether to start the appended text on a new line. Defaults to true.
|
||||
*/
|
||||
fun addText(text: String, isNewLine: Boolean = true)
|
||||
|
||||
/**
|
||||
* It's implementation should execute update()
|
||||
* This method can be called even for [isShown] panels
|
||||
* This method shows the text output or updates the output text if the panel was already shown
|
||||
*/
|
||||
fun show()
|
||||
|
||||
/**
|
||||
* Disposes or hides the output panel, depending on its implementation.
|
||||
* This may free any associated resources.
|
||||
*/
|
||||
fun close()
|
||||
}
|
@ -9,9 +9,25 @@
|
||||
package com.maddyhome.idea.vim.api
|
||||
|
||||
interface VimOutputPanelService {
|
||||
/** TODO we do not need Editor **/
|
||||
/**
|
||||
* Creates a new VimOutputPanel instance for building output without affecting the current panel until displayed.
|
||||
*/
|
||||
// TODO make it possible to pass null instead of editor
|
||||
fun create(editor: VimEditor, context: ExecutionContext): VimOutputPanel
|
||||
|
||||
/**
|
||||
* Retrieves the current VimOutputPanel or creates a new one if none exists.
|
||||
*/
|
||||
fun getOrCreate(editor: VimEditor, context: ExecutionContext): VimOutputPanel
|
||||
|
||||
/**
|
||||
* Returns the currently active VimOutputPanel, if available.
|
||||
*/
|
||||
fun getCurrentOutputPanel(): VimOutputPanel?
|
||||
|
||||
/**
|
||||
* Appends text to the existing output panel or creates a new one with the given text.
|
||||
* Basic method that should be sufficient in most cases.
|
||||
*/
|
||||
fun output(editor: VimEditor, context: ExecutionContext, text: String)
|
||||
}
|
Loading…
Reference in New Issue
Block a user