szn

Bug 511 — resize-pane never updates the layout tree

511. resize-pane resizes the pane grid but not the layout rectangle that renders it

Severity: HIGH Status: ✅ FIXED Files: src/cmd/cmd.zig:1221, src/layout.zig:173, src/window.zig:387-417, src/server/render.zig:289-351

Problem

cmdResizePane computes a target size and then does exactly one thing with it:

// src/cmd/cmd.zig:1221
pane.resizeTerminal(target_w, target_h) catch return .err;
window.invalidateBorderFormat();
return .ok;

The layout tree is untouched. Layout.proportion is assigned in exactly one place — split creation:

// src/layout.zig:173
.proportion = prop,

Every other reference in the tree is a read (window.zig:405,409, render.zig:466,486, server.zig:2194,2200,2298,2309, layout.zig:268,274). There is no setProportion / resize API on Layout.

That matters because the tree, not the pane grid, is the source of truth for geometry:

So after resize-pane -R 10:

Action Observed effect
Grow the pane Nothing — the renderer still clips to the old tree rectangle
Shrink the pane The tail of the pane goes blank (x < cls.items.len fails → Cell.empty())
Any later Window.resize Reverts the grid entirely, because it is recomputed from proportion

server.zig:1179 has the same shape for the resize_left/right/up/down actions, so those are equally ineffective.

Why this is filed rather than assumed intentional

The layout tree is the single source of truth for pane geometry everywhere else in the codebase, and resize-pane is a user-facing command documented in README.md and docs/build-run.md. Bugs #220 (swap_pane_* not resizing panes) and #284 (cmdRotateWindow rotating the pane list but not the tree) are the same class and were both fixed by making the tree follow — this is the remaining member of that family.

Fix

Layout gained a real resize operation, so the tree — not the pane grid — is what moves:

// src/layout.zig
pub fn resizePane(self: *Layout, pane: *Pane, dw: i32, dh: i32) bool

resizePane walks towards the target and calls adjustAxis for each requested axis. adjustAxis prefers the deepest split on the path whose direction matches, then moves that split’s first child by delta cells (negated when the target lives on the second side), clamped so both children keep at least one cell. It writes the proportion back with a half-cell bias — (want + 0.5) / avail — so splitSizes’ truncation reproduces exactly the requested size instead of landing a cell short.

Callers translate the request into a delta and let the tree absorb it:

The previous direct pane.resizeTerminal path is kept as a fallback for windows with no split on the requested axis. That is what a single-pane window is, and it preserves the behaviour the #289 and #391 tests lock in (explicit -x/-y still sets the grid exactly, huge relative adjustments still saturate or error). Layout.resizePane returns false in that case, which is how the caller knows to fall back.

Explicit -x/-y on a multi-pane window is now a delta against the current size rather than an absolute set; when the pane is a direct child of the adjusted split the result is exact, and for a deeper pane it is the closest the single-proportion model can express. That limitation is inherent to representing a layout as split proportions and matches how tmux behaves.

Regression test

resize-pane moves the layout tree, not just the pane grid — bug #511 (src/cmd/cmd.zig) splits a window, records both panes’ findPaneBounds rectangles, runs resize-pane -R 4, and asserts:

Verified with the full suite on Zig 0.16.0 and 0.17.0: 1043/1043 passing on both.