szn

Bug 550 — Screen.useAltScreen does not reset or save/restore scroll_region

550. DECSTBM scroll margins leak across alternate-screen transitions

Severity: MEDIUM
Status: ✅ RESOLVED
Files: src/screen.zig:1722-1763

Problem

Screen.useAltScreen (src/screen.zig:1722-1763) swaps self.grid and self.alt_grid and saves/restores the cursor (saved_cursor / alt_saved_cursor), but never resets or saves/restores self.scroll_region.

If a full-screen TUI application running on the alternate screen sets a DECSTBM scrolling region (e.g. ESC[2;20r) and exits via ESC[?1049l without resetting ESC[r, self.scroll_region remains { .top = 1, .bottom = 19 } on the main screen. Subsequent shell output on the main screen scrolls only inside that sub-region and never pushes lines into scrollback history. Conversely, a scroll region active on the main screen remains active inside the newly entered alternate screen.

Proposed Fix

Save the main screen’s scroll_region (or reset self.scroll_region = null on both entry and exit of useAltScreen, matching xterm/tmux alternate-screen behavior).