diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-28 17:56:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-28 21:05:25 -0300 |
| commit | 96f840a055651b88eb1191772bc4b10fcbbb60ce (patch) | |
| tree | 55ccd6e05fc1f7419f1fef3fb2c7116b556c85d2 /src/pardes.zig | |
| parent | f8c27dbfa9afca327189181a668f2191b499bea5 (diff) | |
| download | pardes-96f840a055651b88eb1191772bc4b10fcbbb60ce.tar.gz pardes-96f840a055651b88eb1191772bc4b10fcbbb60ce.zip | |
layout: a new pane takes rows only from the pane it splits, as acme's coladd does: no column shared out evenly after a placement (only a pane the rounding squeezed, and the new one, lifted to their minimum, restoreMinimaFrom), none when there is no pane to halve (takeRoom: its minimum from the panes with the most to spare), none after a refused pane (it held no weight; absorbVWeight gives back and snaps nothing for it), none after Newcol or the finder column (only a pane whose tag now wraps past its rows is lifted, squeezed); a pane dragged short keeps its rows through all of them; test: a pane made from the middle between two short ones, then Newcol
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 20415e69..3721cc32 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1353,6 +1353,48 @@ test "acme placement: under a pane's text when it has many blank rows, else halv try std.testing.expectEqual(was.y + was.h, p.rects[third].y + p.rects[third].h); } +test "acme placement: a pane made from the middle of a column moves only the one it splits, short ones round it kept short" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 60 }); + defer p.deinit(); + const top = p.active; + _ = try p.setTestFile("one\n"); + p.sync(); + p.setActiveColumn(0); + const middle = p.freeSlot().?; + _ = try p.openTutorView(middle); + exec.placeNew(p, top, top, middle, .doc); + const bottom = p.freeSlot().?; + _ = try p.openTutorView(bottom); + exec.placeNew(p, middle, middle, bottom, .doc); + p.sync(); + // A short pane above and below, dragged under a placement's minimum, + // and the middle one full of text, so it is the one halved. + const full = std.mem.asBytes(&@as([80][2]u8, @splat("x\n".*))); + for ([_]usize{ top, middle, bottom }) |id| panes.File.setContent(p, &p.panes[id].?.file.?, try p.gpa.dupe(u8, full)); + try std.testing.expectEqualSlices(usize, &.{ top, middle, bottom }, p.col_panes[0][0..3]); + const total = p.rects[top].h + p.rects[middle].h + p.rects[bottom].h; + p.panes[top].?.vweight = 2; + p.panes[bottom].?.vweight = 2; + p.panes[middle].?.vweight = @floatFromInt(total - 4); + p.sync(); + const was_top = p.rects[top]; + const was_bottom = p.rects[bottom]; + try std.testing.expect(was_top.h < layout.minRows(p, top)); + const made = p.freeSlot().?; + _ = try p.openTutorView(made); + exec.placeNew(p, middle, middle, made, .doc); + p.sync(); + try std.testing.expectEqual(layout.findPane(p, middle).?.idx + 1, layout.findPane(p, made).?.idx); + try std.testing.expectEqual(was_top, p.rects[top]); + try std.testing.expectEqual(was_bottom, p.rects[bottom]); + // A new column narrows this one, and the short panes keep their rows. + try std.testing.expect(p.executeBuiltinLine(made, "Newcol")); + p.sync(); + try std.testing.expectEqual(@as(usize, 2), p.ncol); + try std.testing.expectEqual(was_top.h, p.rects[top].h); + try std.testing.expectEqual(was_bottom.h, p.rects[bottom].h); +} + test "acme placement: New and 9P's new take the bottom half of the last pane" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); @@ -5273,6 +5315,8 @@ pub const Pardes = struct { // the counter as it is now is the trial's to return to. for (0..p.ncol) |k| _ = layout.columnSerial(p, k); const unspent = p.next_column_serial; + const before_min = layout.minima(p); + const before = p.rects; // Said, not silently nothing: "no space" is 9ns's word for ENOSPC. const c = layout.insertColumnUnannounced(p, col, before_finder) orelse { var said: [96]u8 = undefined; @@ -5282,10 +5326,13 @@ pub const Pardes = struct { "Newcol: no space for a column: this one is too narrow to split"); }; // A narrower column wraps long tags onto more rows, which can leave - // a pane under its tag and two rows: its column's rows are shared - // out again, and where they cannot hold every minimum there is no - // new column, as a size too small is refused. - for (0..p.ncol) |k| if (!layout.columnAtMinimums(p, k) and !layout.shareColumn(p, k)) { + // a pane under its tag and two rows: it takes them back from the + // panes with rows to spare (a pane dragged short keeps its own), + // its column shared out again only where that is not enough, and + // where nothing holds every minimum there is no new column, as a + // size too small is refused. + layout.restoreMinimaFrom(p, &before, &before_min); + for (0..p.ncol) |k| if (layout.squeezed(p, k, &before, &before_min) and !layout.shareColumn(p, k)) { layout.dropColumnUnannounced(p, c); p.next_column_serial = unspent; layout.compute(p); @@ -7567,18 +7614,14 @@ pub const Pardes = struct { } pub fn sync(p: *Pardes) void { - var refused = false; while (p.unplaced.findFirstSet()) |id| { p.unplaced.unset(id); // Refused, it was never there. Its serial is not handed out - // again: one logged or answered names this pane for good. + // again: one logged or answered names this pane for good. Its + // rows, if it had any, go where a closed pane's go; no other + // pane moves (a pane dragged short keeps its rows). if (p.panes[id] != null) p.removePane(id, null) catch {}; - refused = true; } - // A refused pane gone, no pane it squeezed stays under its minimum. - if (refused) for (0..p.ncol) |c| if (!layout.columnAtMinimums(p, c)) { - _ = layout.shareColumn(p, c); - }; // A file opened or closed this step: the kept list follows. p.saveRecent(); tagline.flattenHeaders(p); |
