Severity: HIGH
Status: Fixed
When running commands that output text (e.g. ls, followed by switching windows, then running a program with long output like -h), scrolling up in the terminal scrollback buffer either:
ls output) rather than the most recently scrolled-off text (the top part of -h), cutting off right at the top row of the screen.render.zig:
In src/server/render.zig:renderAll() and renderScreen(), cells from the scrollback history were accessed with:
&pane_grid.history.items[pane_grid.history_start + @as(usize, @intCast(combined_idx))].cells
When the history ring buffer filled up and wrapped around (history_start > 0):
combined_idx is close to hist_len), history_start + combined_idx exceeded pane_grid.history.items.len, resulting in out-of-bounds slice access.history_start + combined_idx < items.len, it read stale entries from the unrotated beginning of the ring buffer instead of the actual logical lines, displaying previous commands (like ls) instead of recent output.mode_copy.zig:
src/mode_copy.zig in getCellAtOffset and isLineWrapped also performed direct indexing:
const line = &grid.history.items[grid.history_start + combined_idx];
instead of calling grid.getHistoryLine(combined_idx). Additionally, visible lines used grid.lines.items[visible_y] instead of grid.getLine(visible_y), ignoring grid.start_index.
Inconsistent modulo in grid.zig:
clearHistory, setHistoryLimit, scrollUp, and scrollDown in src/grid.zig used % self.history_limit rather than % self.history.items.len. When history.items.len < history_limit and history_start > 0, ring index calculations produced indices larger than history.items.len.
history-limit inheritance in Session.newWindow:
src/session.zig:newWindow() did not propagate the session’s history-limit option to newly spawned window panes, unlike Session.init.src/server/render.zig, updated renderAll and renderScreen to use pane_grid.getHistoryLine(@as(usize, @intCast(combined_idx))) and grid.getLine(@intCast(visible_y)) consistently.src/mode_copy.zig, updated getCellAtOffset and isLineWrapped to use grid.getHistoryLine(combined_idx) and grid.getLine(@intCast(visible_y)).src/grid.zig, standardized all circular deque indexing to % self.history.items.len and protected scrollUp/scrollDown and reflowCursorInternal error rollback against ring state corruption.src/session.zig, added history-limit propagation to Session.newWindow.