mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[terminal] correct startOffset in TerminalOutputModelListener.afterContentChanged when update exceeds maxCapacity
GitOrigin-RevId: 4e9b06974f140624d16a2f13f084662d4be09f2f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2bcb261ee9
commit
bf280c6f4a
+2
-1
@@ -13,6 +13,7 @@ import org.jetbrains.plugins.terminal.block.output.TerminalOutputHighlightingsSn
|
||||
import org.jetbrains.plugins.terminal.block.output.TextStyleAdapter
|
||||
import org.jetbrains.plugins.terminal.block.session.StyleRange
|
||||
import org.jetbrains.plugins.terminal.block.ui.BlockTerminalColorPalette
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* [maxOutputLength] limits the length of the document. Zero means unlimited length.
|
||||
@@ -92,7 +93,7 @@ internal class TerminalOutputModelImpl(
|
||||
|
||||
val trimmedCount = trimToSize()
|
||||
|
||||
return replaceStartOffset - trimmedCount
|
||||
return max(0, replaceStartOffset - trimmedCount)
|
||||
}
|
||||
|
||||
/** Returns trimmed characters count */
|
||||
|
||||
+33
@@ -9,6 +9,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.TerminalOutputModelListener
|
||||
import org.jetbrains.plugins.terminal.block.session.StyleRange
|
||||
import org.jetbrains.plugins.terminal.block.ui.BlockTerminalColorPalette
|
||||
import org.jetbrains.plugins.terminal.reworked.util.TerminalSessionTestUtil
|
||||
@@ -140,6 +141,38 @@ internal class TerminalOutputModelTest : BasePlatformTestCase() {
|
||||
assertEquals(expectedHighlightingsSnapshot, model.getHighlightings())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `update exceeds maxCapacity`() = runBlocking(Dispatchers.EDT) {
|
||||
val model = TerminalSessionTestUtil.createOutputModel(maxLength = 10)
|
||||
val startOffsets = mutableListOf<Int>()
|
||||
model.addListener(testRootDisposable, object: TerminalOutputModelListener {
|
||||
override fun afterContentChanged(startOffset: Int) {
|
||||
startOffsets.add(startOffset)
|
||||
}
|
||||
})
|
||||
|
||||
model.update(0, """
|
||||
abcdef
|
||||
ghijkl
|
||||
""".trimIndent(), emptyList())
|
||||
|
||||
assertEquals("""
|
||||
def
|
||||
ghijkl
|
||||
""".trimIndent(), model.document.text)
|
||||
|
||||
model.update(1, """
|
||||
mnopqrs
|
||||
tuvwxyz
|
||||
""".trimIndent(), emptyList())
|
||||
|
||||
assertEquals("""
|
||||
rs
|
||||
tuvwxyz
|
||||
""".trimIndent(), model.document.text)
|
||||
assertEquals(listOf(0, 0), startOffsets)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `update editor content from the start when some lines were trimmed already (clear)`() = runBlocking(Dispatchers.EDT) {
|
||||
val model = TerminalSessionTestUtil.createOutputModel(maxLength = 10)
|
||||
|
||||
Reference in New Issue
Block a user