summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:37:54 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:59 -0300
commit3624c0e0bf0b455c4323fc8ba9f10a305f11afb2 (patch)
treec658d6c0f803fcd9a39895cfccd2c7d90a5be0bf /src
parentef78fbd9cefc17da4f4be82545a055ea4c6b591c (diff)
downloadpardes-3624c0e0bf0b455c4323fc8ba9f10a305f11afb2.tar.gz
pardes-3624c0e0bf0b455c4323fc8ba9f10a305f11afb2.zip
layout: movePlacement and movePane read each pane's rows off `rects` in a line where each built them from the columns' lists in seven; splitBelow's snap of its column's weights is snapColWeights; canSplitColumn folds into splitColumn, which looked its source up twice (the Newcol test asks canSplitCol of the column)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/layout.zig40
-rw-r--r--src/pardes.zig2
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"));