Lite Terminal: don't repaint a pasted block taller than the viewport - #1867
Open
globalerp-mhess wants to merge 1 commit into
Open
Lite Terminal: don't repaint a pasted block taller than the viewport#1867globalerp-mhess wants to merge 1 commit into
globalerp-mhess wants to merge 1 commit into
Conversation
Coloring a submitted paste repainted the input in place: save the cursor, move up the number of rows computed for the input, erase, redraw, restore. That upward move is unfulfillable once the input is taller than the window — `\x1b[nA` stops at the top row — so the redraw started as many rows too low as the input exceeded the viewport, leaving the top of the original block on screen and the command's output inside the second copy. Measured with a 31-line paste: in a 49-row window the handler moves up 30 rows and the result is correct; in a 20-row window it computes the same 30 and lands 11 rows off, which is exactly the overflow. Input that arrives with its own carriage return is submitted straight away, so its echo is never corrected by a later keystroke. Hold that echo back and let the `color` handler write the colored text in its place. A plain write at the position the raw text would have occupied cannot be misplaced, so no arithmetic is involved and the height of the block stops mattering. If no coloring arrives inside the existing 100 ms window, the raw text is written instead: uncolored as before, but never invisible. Typed input keeps the existing repaint, which is correct for it — every keystroke colors a block that is already on screen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
Thanks for the PR @globalerp-mhess! @isc-klu This seems fine to me but I want your review since it's related to your change. |
isc-klu
approved these changes
Sep 10, 2026
| @@ -297,6 +300,13 @@ class WebSocketTerminal implements vscode.Pseudoterminal { | |||
| case "color": { | |||
| // Outdated: the input is no longer on screen | |||
| if (this._state != "prompt") break; | |||
Collaborator
There was a problem hiding this comment.
@isc-bsaviano I am not sure if we still need to check this._state but we can leave it as a future task for ourselves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1866 and #1862, which fixed the coloring itself. One case still misdraws: a paste
taller than the terminal window.
Coloring a submitted paste repaints the input in place — save the cursor, move up the number of rows
computed for the input, erase, redraw, restore. That upward move is unfulfillable once the input is
taller than the window, because
\x1b[nAstops at the top row. The redraw then starts as many rowstoo low as the input exceeds the viewport, which leaves the top of the original block on screen and
puts the command's output inside the second copy.
Measured with a 31-line paste of
set a01=1…set a30=30: in a 49-row window the handler moves up30 rows and the result is correct; in a 20-row window it computes the same 30 and lands 11 rows off —
exactly the overflow. Nothing in the class can notice, since
setDimensionsreceivesdimensions.rowsbut onlycolumnsis kept. On the commit before #1866 the same paste renderscorrectly, so it is the repaint and not the raw echo: a downward correction clamping at the bottom
row happens to land where it wants to be, an upward one does not.
The change: input that arrives with its own carriage return is submitted straight away, so its echo
is never corrected by a later keystroke. Hold that echo back and let the
colorhandler write thecolored text in its place. A plain write at the position the raw text would have occupied has no
arithmetic in it, so the height of the block stops mattering. The 100 ms window and the
_state != "prompt"guard from #1866 are unchanged; if no coloring arrives in time the raw text iswritten instead — uncolored as before, but never invisible. Typed input keeps the existing repaint,
which is correct for it, since every keystroke colors a block already on screen.
Verified against IRIS 2026.3.0AI: the 31-line paste is colored and correct in a 20-row window, where
it was misdrawn before, and unchanged in a tall window; typed multi-line input with Enter behaves as
before.
Edit for clarification:
With #1866 in place — 31-line paste into a 20-row window. The block is drawn twice and the

command's output lands inside the second copy:
Same paste, same window, with this change:
