mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[terminal] encapsulate terminalCommandBlockHighlighters in CompositeTerminalTextHighlighter
(cherry picked from commit 647e39168b615d156347c8108cf02d30230c8aca) IJ-CR-146871 GitOrigin-RevId: 9bfef4d55ca6fafef5ef79cd07836831fb8f99a0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7e9f8fe9f3
commit
0c378f7061
@@ -18,8 +18,6 @@ import org.jetbrains.plugins.terminal.block.BlockTerminalScopeProvider
|
||||
import org.jetbrains.plugins.terminal.block.TerminalFocusModel
|
||||
import org.jetbrains.plugins.terminal.block.hyperlinks.TerminalHyperlinkHighlighter
|
||||
import org.jetbrains.plugins.terminal.block.output.highlighting.CompositeTerminalTextHighlighter
|
||||
import org.jetbrains.plugins.terminal.block.output.highlighting.TerminalCommandBlockHighlighter
|
||||
import org.jetbrains.plugins.terminal.block.output.highlighting.TerminalCommandBlockHighlighterProvider.Companion.COMMAND_BLOCK_HIGHLIGHTER_PROVIDER_EP_NAME
|
||||
import org.jetbrains.plugins.terminal.block.prompt.TerminalPromptRenderingInfo
|
||||
import org.jetbrains.plugins.terminal.block.session.*
|
||||
import org.jetbrains.plugins.terminal.block.ui.executeInBulk
|
||||
@@ -62,16 +60,11 @@ internal class TerminalOutputController(
|
||||
|
||||
private val nextBlockCanBeStartedQueue: Queue<() -> Unit> = LinkedList()
|
||||
|
||||
private val commandBlockHighlighters: List<TerminalCommandBlockHighlighter> = COMMAND_BLOCK_HIGHLIGHTER_PROVIDER_EP_NAME
|
||||
.extensionList
|
||||
.map { it.getHighlighter(editor.colorsScheme) }
|
||||
|
||||
init {
|
||||
editor.putUserData(IS_OUTPUT_EDITOR_KEY, true)
|
||||
editor.highlighter = CompositeTerminalTextHighlighter(
|
||||
outputModel,
|
||||
textHighlighter,
|
||||
commandBlockHighlighters.toMutableList(),
|
||||
session
|
||||
)
|
||||
session.model.addTerminalListener(this)
|
||||
|
||||
@@ -4,6 +4,7 @@ package org.jetbrains.plugins.terminal.block.output.highlighting
|
||||
import com.intellij.openapi.editor.highlighter.EditorHighlighter
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterClient
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
|
||||
/**
|
||||
* A `CompositeEditorHighlighter` combines multiple editor highlighters to allow for different highlighting behaviors.
|
||||
@@ -15,10 +16,14 @@ import com.intellij.openapi.editor.highlighter.HighlighterIterator
|
||||
* at least two switchable highlighters are applicable
|
||||
* @property switchableEditorHighlighters List of switchable editor highlighters to combine in this composite highlighter
|
||||
*/
|
||||
open class CompositeEditorHighlighter(
|
||||
abstract class CompositeEditorHighlighter(
|
||||
private val defaultEditorHighlighter: EditorHighlighter,
|
||||
private val switchableEditorHighlighters: List<SwitchableEditorHighlighter>
|
||||
) : EditorHighlighter {
|
||||
|
||||
protected abstract val switchableEditorHighlighters: List<SwitchableEditorHighlighter>
|
||||
@RequiresEdt(generateAssertion = false)
|
||||
get
|
||||
|
||||
private var editor: HighlighterClient? = null
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,11 +5,13 @@ import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.intellij.openapi.util.ClearableLazyValue
|
||||
import org.jetbrains.plugins.terminal.block.output.CommandBlock
|
||||
import org.jetbrains.plugins.terminal.block.output.TerminalOutputModel
|
||||
import org.jetbrains.plugins.terminal.block.output.TerminalOutputModelListener
|
||||
import org.jetbrains.plugins.terminal.block.output.TerminalTextHighlighter
|
||||
import org.jetbrains.plugins.terminal.block.output.highlighting.TerminalCommandBlockHighlighterProvider.Companion.COMMAND_BLOCK_HIGHLIGHTER_PROVIDER_EP_NAME
|
||||
import org.jetbrains.plugins.terminal.block.ui.invokeLater
|
||||
|
||||
/**
|
||||
* A composite implementation of EditorHighlighter, which allows for highlighting different command blocks using different highlighters.
|
||||
@@ -19,11 +21,16 @@ import org.jetbrains.plugins.terminal.block.output.highlighting.TerminalCommandB
|
||||
* 2) at least two highlighters are applicable
|
||||
*/
|
||||
internal class CompositeTerminalTextHighlighter(
|
||||
terminalOutputModel: TerminalOutputModel,
|
||||
private val terminalOutputModel: TerminalOutputModel,
|
||||
terminalTextHighlighter: TerminalTextHighlighter,
|
||||
private val terminalCommandBlockHighlighters: MutableList<TerminalCommandBlockHighlighter>,
|
||||
parentDisposable: Disposable,
|
||||
) : CompositeEditorHighlighter(terminalTextHighlighter, terminalCommandBlockHighlighters) {
|
||||
) : CompositeEditorHighlighter(terminalTextHighlighter) {
|
||||
|
||||
private val terminalCommandBlockHighlighters: ClearableLazyValue<List<TerminalCommandBlockHighlighter>> = ClearableLazyValue.create {
|
||||
COMMAND_BLOCK_HIGHLIGHTER_PROVIDER_EP_NAME
|
||||
.extensionList
|
||||
.map { it.getHighlighter(terminalOutputModel.editor.colorsScheme) }
|
||||
}
|
||||
|
||||
init {
|
||||
terminalOutputModel.addListener(object : TerminalOutputModelListener {
|
||||
@@ -33,19 +40,22 @@ internal class CompositeTerminalTextHighlighter(
|
||||
})
|
||||
COMMAND_BLOCK_HIGHLIGHTER_PROVIDER_EP_NAME.addExtensionPointListener(object : ExtensionPointListener<TerminalCommandBlockHighlighterProvider> {
|
||||
override fun extensionRemoved(extension: TerminalCommandBlockHighlighterProvider, pluginDescriptor: PluginDescriptor) {
|
||||
synchronized(terminalCommandBlockHighlighters) {
|
||||
terminalCommandBlockHighlighters.removeIf { highlighter -> highlighter::class == extension.getHighlighter(terminalOutputModel.editor.colorsScheme)::class }
|
||||
invokeLater {
|
||||
terminalCommandBlockHighlighters.drop()
|
||||
}
|
||||
}
|
||||
}, parentDisposable)
|
||||
}
|
||||
|
||||
override val switchableEditorHighlighters: List<SwitchableEditorHighlighter>
|
||||
get() = terminalCommandBlockHighlighters.value
|
||||
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
terminalCommandBlockHighlighters.forEach { it.documentChanged(event) }
|
||||
terminalCommandBlockHighlighters.value.forEach { it.documentChanged(event) }
|
||||
}
|
||||
|
||||
fun setCommandBlock(block: CommandBlock) {
|
||||
terminalCommandBlockHighlighters.forEach { highlighter ->
|
||||
terminalCommandBlockHighlighters.value.forEach { highlighter ->
|
||||
highlighter.applyHighlightingInfoToBlock(block)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user