Skip to content

fix: scroll a partial DECSTBM region within itself, not below it - #236

Open
smohekey wants to merge 1 commit into
TerminalStudio:masterfrom
smohekey:fix/partial-scroll-region
Open

fix: scroll a partial DECSTBM region within itself, not below it#236
smohekey wants to merge 1 commit into
TerminalStudio:masterfrom
smohekey:fix/partial-scroll-region

Conversation

@smohekey

Copy link
Copy Markdown

Problem

When the cursor is on the bottom margin and a line feed occurs, index() grows the scrollback (inserts a line just below the last visible row) whenever marginTop == 0. That's only correct for a full-height scroll — a region whose bottom is the last row of the screen.

For a partial region (top margin 0, but bottom margin above the last row — e.g. ESC[1;9r on a 24-row screen), it inserts a line below the region, shoving everything underneath out of place instead of scrolling the region's own rows. Applications that redraw part of an inline UI with partial scroll regions — ratatui's inline viewport, used by the Codex CLI — get scrambled output.

Reproduce

final terminal = Terminal()..resize(10, 6);
terminal.write('L0\r\nL1\r\nL2\r\nL3\r\nL4\r\nL5');
terminal.write('\x1b[1;3r');   // partial scroll region: rows 1..3 of 6
terminal.write('\x1b[3;1H\n'); // index on the bottom margin -> scroll the region
// before: rows below the region (L3/L4/L5) get shoved down
// after:  rows below the region are untouched; only rows 1..3 scroll

Fix

Gate the scrollback-growth path on the region also reaching the last row (marginBottom == viewHeight - 1); otherwise scroll within the region (scrollUp).

Test

Adds test/src/core/buffer/scroll_region_test.dart asserting the rows below a scrolled partial region are undisturbed and the region itself scrolls correctly.

When the cursor is on the bottom margin and a line feed occurs, `index()` grew
the scrollback (inserting a line just below the last visible row) whenever
`marginTop == 0`. That's only correct for a *full-height* scroll — a region
whose bottom is the last row of the screen. For a *partial* region (top margin 0
but bottom margin above the last row) it inserted a line *below* the region,
shoving everything underneath out of place instead of scrolling the region's own
rows.

Gate the scrollback-growth path on the region also reaching the last row
(`marginBottom == viewHeight - 1`); otherwise scroll within the region.

Applications that redraw part of an inline UI with partial scroll regions (e.g.
ratatui's inline viewport, used by the Codex CLI) were getting scrambled output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant