From 9ec1bd4f5aa9219da94ed77095200e0699b639cf Mon Sep 17 00:00:00 2001 From: Sergei Tachenov Date: Tue, 11 Feb 2025 18:17:23 +0200 Subject: [PATCH] IJPL-176818 [reworked terminal] Update cursor on document changes This fixes the case when the cursor offset hasn't changed because something was appended to the document and the same number of characters was removed from the beginning to maintain the size. The offset stays the same, and therefore isn't emitted from the flow. In such cases the cursor would only be repainted later due to some other event, such as blinking. GitOrigin-RevId: 5eb1dc1c6adfd3854c1290cd31806f48a1a0edee --- .../terminal/block/reworked/TerminalCursorPainter.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/reworked/TerminalCursorPainter.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/reworked/TerminalCursorPainter.kt index 4da24674853d..d5cd31a4e9f1 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/block/reworked/TerminalCursorPainter.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/block/reworked/TerminalCursorPainter.kt @@ -78,6 +78,17 @@ internal class TerminalCursorPainter private constructor( updateCursor(curCursorState) } }, coroutineScope.asDisposable()) + + // Handling the case when: + // 0. The cursor is at the end of the document. + // 1. Something was appended to the document. + // 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) { + updateCursor(curCursorState) + } + }) } @RequiresEdt