Fix scrollback corruption when editor exceeds terminal height#147
Merged
Fix scrollback corruption when editor exceeds terminal height#147
Conversation
bananabot9000
approved these changes
Mar 29, 2026
Collaborator
bananabot9000
left a comment
There was a problem hiding this comment.
The full terminal rendering redesign from Issue #146, implemented across 5 micro-session stages. 1,307 additions, 167 tests, matches the design doc.
Architecture verified:
- Screen interface + StdoutScreen + MockScreen (with ANSI interpreter and scrollback violation tracking)
- Layout -- pure function, correct component ordering, wrapLine with stringWidth
- Viewport -- 31 lines, cursor chasing, resize capping
- Renderer (as TerminalRenderer.ts -- smart macOS case collision avoidance) -- sync markers, zone-aware rendering
- terminal.ts -- buildSticky()/clearStickyZone() replaced with renderZone() pipeline through Layout > Viewport > Renderer
Bugs caught during Stage 5 (good catches):
- Viewport padding caused scrollback violations on first render when cursor was not at row 0 -- fixed by trimming trailing empty rows before writing
- writeHistory re-rendered stale lastFrame with cleared question still visible -- fixed by splitting into writeHistoryLine + fresh renderZone()
Minor notes (non-blocking):
- wrapLine iterates by code point not grapheme cluster (Intl.Segmenter would handle compound emoji at wrap boundaries). Not a regression.
- Deprecated writeHistory on Renderer -- can it be removed if only writeHistoryLine + external render is used?
The one invariant holds: the renderer never writes more rows than screen.rows. Scrollback corruption is now structurally impossible.
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.
Summary
Complete rewrite of the terminal functionality.
Terminal no longer writes more rows than
screen.rows, eliminating scrollback corruption when the editor exceeds terminal height.Changes
buildSticky()/clearStickyZone()screen.rowswith cursor chasing on scroll and resizeRelated Issues
Closes #146
Co-Authored-By: Claude noreply@anthropic.com