From cc0c8a764fead1e5e6331bd3779135babde08ae4 Mon Sep 17 00:00:00 2001 From: Andrew Stein Date: Sun, 5 Jul 2026 20:17:45 -0500 Subject: [PATCH] Fix: caret can fall off-screen after typing on long lines AddCharacter was the only edit operation still calling the line-granularity ScrollLineIntoViewIfOutside to keep the caret visible. Every other edit operation (Backspace, Delete, AddNewLine, Undo, Redo) uses UpdateScrollToShowCursor. Because ScrollLineIntoViewIfOutside does not scroll while the caret stays on the same (long) line, a caret typed past the right edge could end up outside the rendered area. Switch AddCharacter to the shared UpdateScrollToShowCursor helper for consistent caret-follow behavior. --- TextControlBox/Core/Text/TextActionManager.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TextControlBox/Core/Text/TextActionManager.cs b/TextControlBox/Core/Text/TextActionManager.cs index 8bf7f5f..a78fab4 100644 --- a/TextControlBox/Core/Text/TextActionManager.cs +++ b/TextControlBox/Core/Text/TextActionManager.cs @@ -500,8 +500,15 @@ public void AddCharacter(string text, bool ignoreSelection = false, bool ignoreI } eventsManager.CallTextChanged(); - scrollManager.ScrollLineIntoViewIfOutside(cursorManager.LineNumber, false); - + // Keep the caret visible after typing using the same helper every other edit + // operation uses. Backspace, Delete, AddNewLine, Undo and Redo all call + // UpdateScrollToShowCursor; AddCharacter was the only one still using the + // line-granularity ScrollLineIntoViewIfOutside, which does not scroll while the + // caret stays on the same (long) line, so a caret typed past the right edge could + // fall outside the rendered area. Using the shared helper makes the caret follow + // consistent with the rest of the edit operations. + scrollManager.UpdateScrollToShowCursor(false); + canvasUpdateManager.UpdateAll(); }