diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout.zig | 40 | ||||
| -rw-r--r-- | src/pardes.zig | 2 |
2 files changed, 13 insertions, 29 deletions
diff --git a/src/layout.zig b/src/layout.zig index f687cac7..a3fb9b8e 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -275,13 +275,9 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme // between panes, that is how a terminal resizes them. if (cur_y >= top and cur_y < top + span_h and (src.idx == 0 or cur_y <= top)) return null; } - var heights: [MAX_PANES]u16 = @splat(0); - for (0..p.ncol) |c| { - for (0..p.col_n[c]) |k| { - const pid = p.col_panes[c][k]; - heights[pid] = p.rects[pid].h; - } - } + // Every pane's rows as laid out; only the placed panes' are read. + var heights: [MAX_PANES]u16 = undefined; + for (&heights, p.rects) |*h, r| h.* = r.h; if (p.col_n[src.col] > span_end - src.idx) { const sib = if (src.idx > 0) p.col_panes[src.col][src.idx - 1] else p.col_panes[src.col][span_end]; heights[sib] +|= span_h; @@ -335,13 +331,8 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void { var moved: [MAX_PANES]usize = undefined; @memcpy(moved[0..count], p.col_panes[src.col][src.idx..span_end]); const source_multi = p.col_n[src.col] > count; - var heights: [MAX_PANES]u16 = @splat(0); - for (0..p.ncol) |c| { - for (0..p.col_n[c]) |k| { - const pid = p.col_panes[c][k]; - heights[pid] = p.rects[pid].h; - } - } + var heights: [MAX_PANES]u16 = undefined; + for (&heights, p.rects) |*h, r| h.* = r.h; var span_h: u16 = 0; for (moved[0..count]) |m| span_h +|= heights[m]; for (moved[0..count]) |m| removePane(p, m); @@ -874,13 +865,9 @@ fn blankRows(p: *const Pardes, id: usize) u16 { return rows -| @as(u16, @intCast(@min(used, rows))); } -pub fn canSplitColumn(p: *Pardes, source_id: usize) bool { - if (source_id >= MAX_PANES or p.panes[source_id] == null) return false; - const source = findPane(p, source_id) orelse return false; - return canSplitCol(p, source.col); -} - -fn canSplitCol(p: *Pardes, col: usize) bool { +/// Whether column `col` has the width and the weight to halve for a new +/// column beside it. +pub fn canSplitCol(p: *Pardes, col: usize) bool { if (p.ncol >= MAX_COLS or col >= p.ncol) return false; // Refresh derived widths: public layout surgery may be chained between // syncs, and a cached width must never admit a now-too-narrow split. @@ -948,8 +935,9 @@ pub fn insertColumnUnannounced(p: *Pardes, col: usize, before: bool) ?usize { /// source itself when its column keeps another pane. pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { if (id >= MAX_PANES or p.panes[id] == null) return false; - if (!canSplitColumn(p, source_id)) return false; + if (source_id >= MAX_PANES or p.panes[source_id] == null) return false; const source = findPane(p, source_id) orelse return false; + if (!canSplitCol(p, source.col)) return false; if (id == source_id) { if (p.col_n[source.col] <= 1) return false; _ = absorbVWeight(p, id, null); @@ -1006,12 +994,8 @@ pub fn splitBelow(p: *Pardes, src_id: usize, nw: *Pane) void { // has them: a boot layout splits before any row is laid out. const least = @min(min_body_rows, body); const keep = std.math.clamp(cur, least, @max(least, body -| (BOX_H + 3))); - if (findPane(p, src_id)) |f| for (0..p.col_n[f.col]) |k| { - const pid = p.col_panes[f.col][k]; - if (p.panes[pid]) |pp| if (pp != nw and !pp.collapsed) { - pp.vweight = @floatFromInt(@max(1, p.rects[pid].h)); - }; - }; + // The new pane's weight, and the source's, are set just below. + if (findPane(p, src_id)) |f| snapColWeights(p, f.col); if (!src.collapsed) src.vweight = @floatFromInt(tag_h + keep); nw.vweight = @floatFromInt(@max(1, src_h -| (tag_h + keep))); if (nw.file) |f| if (!panes.Output.fileTraits(f.output).doc) { diff --git a/src/pardes.zig b/src/pardes.zig index bd79741f..72201360 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -3220,7 +3220,7 @@ test "Newcol refuses an unsplittable restored weight before spawning" { try std.testing.expect(p.col_weight[0] > std.math.maxInt(u64) / 2); try std.testing.expect(p.col_weight[0] % 2 == 1); - try std.testing.expect(!layout.canSplitColumn(p, 0)); + try std.testing.expect(!layout.canSplitCol(p, layout.findPane(p, 0).?.col)); const panes_before = p.panes; const serial_before = p.next_serial; try std.testing.expect(p.executeBuiltinLine(0, "Newcol")); |
