szn

Bug 249 — History restoration order inversion in Grid.scrollDown

249. History restoration order inversion in Grid.scrollDown

File: src/grid.zig:255–275 Severity: CRITICAL Status: ✅ FIXED — restored LIFO stack popping order using history.pop(); reset history_start and cleared capacity when history becomes empty. Updated unit tests.

Grid.scrollDown was modified in bug #216 to take history.items[history_start] (FIFO queue, oldest line first) instead of history.pop() (LIFO stack, newest line first). Because scrollUp appends lines to history sequentially, history_start contains the oldest line while pop() yields the newest (most recently scrolled off) line. Restoring multiple scrolled-off lines back into the active visible grid restores them in reverse order (oldest first instead of newest first), scrambling scrollback lines.

Fix: Restore pop() behavior (taking history.items[history.items.len - 1]) while guarding with if (self.history.items.len <= self.history_start) return;.