szn

Bug 453 — reflowCursorInternal trims trailing screen rows on width change, stealing history lines into visible screen

453. Width resize/split drops trailing screen rows and pulls history into view

Severity: MEDIUM
Status: ❌ FALSE POSITIVE (intentional design)
Files: src/grid.zig, docs/text_reflow.md


Resolution

On closer inspection against the architecture specification in docs/text_reflow.md, this is deliberate and tested behavior:

  1. Unified Reflow Model: Per docs/text_reflow.md Section 5:
    • Step 1 (Flattening): “The algorithm scans the grid backward to find the process_limit (the last non-empty row containing actual text). Trailing empty rows at the bottom of the screen are ignored to prevent them from scrolling active text into history.”
    • Step 3 (Layout Reconstruction): “If the total number of re-wrapped lines is smaller than or equal to the screen height, they are drawn directly to the visible grid, and empty lines are padded at the bottom. If the content exceeds the screen height, the oldest lines scroll out of the visible screen and are pushed cleanly into the scrollback history buffer (grid.history).”
  2. Dedicated Test Suite Coverage: In src/grid.zig:1418, test "setSize reflows content" explicitly tests and asserts this exact behavior:
    // Content is reflowed: all lines (history + visible) are rewrapped.
    // History A,B,C come first, then visible D,E
    try testing.expectEqual(@as(u21, 'A'), grid.getCell(0, 0).char);
    ...
    try testing.expectEqual(@as(usize, 0), grid.history.items.len);
    
  3. Scope of Bug #347: Bug #347 addressed an issue specifically with forceReflowCursor upon copy-mode entry (enterCopyMode), where the window geometry was not changing (new_width == self.width), so no reflow or layout shifting should occur. On genuine width changes (new_width != self.width), unwrapping logical text and filling the screen with recent content is the designed behavior.