[terminal] IJPL-183992 Refactor: add model parameter to the TerminalOutputModelListener methods

So it will be possible to use the single listener object in multiple models.

(cherry picked from commit 2761d0f93f20ab9d6f6bd222e5ac9bf46ebcac71)

IJ-CR-160917

GitOrigin-RevId: 4d1d84ee31678fab576bb8c45e9368f07e28d9de
This commit is contained in:
Konstantin Hudyakov
2025-04-30 16:55:06 +02:00
committed by intellij-monorepo-bot
parent 483e3a12a0
commit dd5378dbe6
7 changed files with 11 additions and 10 deletions

View File

@@ -280,11 +280,11 @@ internal class ReworkedTerminalView(
// Document modifications can change the scroll position.
// Mark them with the corresponding flag to indicate that this change is not caused by the explicit user action.
model.addListener(parentDisposable, object : TerminalOutputModelListener {
override fun beforeContentChanged() {
override fun beforeContentChanged(model: TerminalOutputModel) {
editor.isTerminalOutputScrollChangingActionInProgress = true
}
override fun afterContentChanged(startOffset: Int) {
override fun afterContentChanged(model: TerminalOutputModel, startOffset: Int) {
editor.isTerminalOutputScrollChangingActionInProgress = false
// Also repaint the changed part of the document to ensure that highlightings are properly painted.

View File

@@ -100,7 +100,7 @@ internal class TerminalCursorPainter private constructor(
// 2. An equal amount of text was removed from the beginning, so that the max document size is maintained.
// 3. As a result, the logical offset of the cursor stayed the same, but we still need to repaint it.
outputModel.addListener(coroutineScope.asDisposable(), object : TerminalOutputModelListener {
override fun afterContentChanged(startOffset: Int) {
override fun afterContentChanged(model: TerminalOutputModel, startOffset: Int) {
// This listener exists to handle the case when the offset has not changed,
// but it must also work correctly when the offset has in fact changed.
// In that case, the offset is updated before this listener is invoked,

View File

@@ -48,7 +48,7 @@ internal class TerminalOutputScrollingModelImpl(
}
outputModel.addListener(coroutineScope.asDisposable(), object : TerminalOutputModelListener {
override fun afterContentChanged(startOffset: Int) {
override fun afterContentChanged(model: TerminalOutputModel, startOffset: Int) {
if (shouldScrollToCursor) {
// We already called in an EDT, but let's update the scroll later to not block output model updates.
coroutineScope.launch(Dispatchers.EDT + ModalityState.any().asContextElement()) {

View File

@@ -140,7 +140,7 @@ class TerminalOutputModelImpl(
* [block] should return an offset from which document content was changed.
*/
private fun changeDocumentContent(block: () -> Int) {
dispatcher.multicaster.beforeContentChanged()
dispatcher.multicaster.beforeContentChanged(this)
contentUpdateInProgress = true
val changeStartOffset = try {
@@ -150,7 +150,7 @@ class TerminalOutputModelImpl(
contentUpdateInProgress = false
}
dispatcher.multicaster.afterContentChanged(changeStartOffset)
dispatcher.multicaster.afterContentChanged(this, changeStartOffset)
}
override fun getHighlightings(): TerminalOutputHighlightingsSnapshot {

View File

@@ -9,11 +9,11 @@ interface TerminalOutputModelListener : EventListener {
/**
* Called before actual changes in the document and highlightings in [TerminalOutputModel.updateContent].
*/
fun beforeContentChanged() {}
fun beforeContentChanged(model: TerminalOutputModel) {}
/**
* Called after changing the document and highlightings in [TerminalOutputModel.updateContent].
* @param startOffset offset from which document was updated.
*/
fun afterContentChanged(startOffset: Int) {}
fun afterContentChanged(model: TerminalOutputModel, startOffset: Int) {}
}

View File

@@ -136,7 +136,7 @@ class TerminalHyperlinkHighlighter private constructor(
fun install(project: Project, model: TerminalOutputModel, editor: Editor, coroutineScope: CoroutineScope): TerminalHyperlinkHighlighter {
val hyperlinkHighlighter = TerminalHyperlinkHighlighter(project, editor, coroutineScope)
model.addListener(coroutineScope.asDisposable(), object : TerminalOutputModelListener {
override fun afterContentChanged(startOffset: Int) {
override fun afterContentChanged(model: TerminalOutputModel, startOffset: Int) {
hyperlinkHighlighter.highlightHyperlinks(startOffset)
}
})

View File

@@ -11,6 +11,7 @@ import kotlinx.coroutines.runBlocking
import org.jetbrains.plugins.terminal.block.output.HighlightingInfo
import org.jetbrains.plugins.terminal.block.output.TerminalOutputHighlightingsSnapshot
import org.jetbrains.plugins.terminal.block.output.TextStyleAdapter
import org.jetbrains.plugins.terminal.block.reworked.TerminalOutputModel
import org.jetbrains.plugins.terminal.block.reworked.TerminalOutputModelListener
import org.jetbrains.plugins.terminal.block.ui.BlockTerminalColorPalette
import org.jetbrains.plugins.terminal.reworked.util.TerminalTestUtil
@@ -148,7 +149,7 @@ internal class TerminalOutputModelTest : BasePlatformTestCase() {
val model = TerminalTestUtil.createOutputModel(maxLength = 10)
val startOffsets = mutableListOf<Int>()
model.addListener(testRootDisposable, object: TerminalOutputModelListener {
override fun afterContentChanged(startOffset: Int) {
override fun afterContentChanged(model: TerminalOutputModel, startOffset: Int) {
startOffsets.add(startOffset)
}
})