From 9299281492d63e549ab274034efb59ab4e9d96f6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 13:11:11 -0300 Subject: Search converge 6/6: SearchPlace column, the finder column at the right edge holding the query panes; n/N in a frozen query pane; the design doc --- src/Finder.zig | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 src/Finder.zig (limited to 'src/Finder.zig') diff --git a/src/Finder.zig b/src/Finder.zig new file mode 100644 index 00000000..a2b8f89f --- /dev/null +++ b/src/Finder.zig @@ -0,0 +1,240 @@ +//! The finder column: where query panes go with `SearchPlace column`, the +//! alternative to attaching them under the pane that asked (lifted from +//! the column prototype, cut to its placement). A column with a role at +//! the right edge: the first search opens it and the other columns give it +//! its share once, each in proportion to its weight; after that no pane +//! outside it moves for a search. Its width is a share of the window, not a +//! column weight (layout.compute), so it opens and closes without rounding +//! anyone's width off. Its panes are a recency stack: the newest query pane +//! on top and open, the older ones folded to their tags. A pane opened +//! from a row goes to the column of the pane the query searches, never in +//! here. Its last pane gone, the column goes and every other is as wide as +//! before it came. The role is the column's serial. +const Finder = @This(); + +const std = @import("std"); +const pardes = @import("pardes.zig"); +const layout = @import("layout.zig"); +const config = @import("config.zig"); +const panes = @import("panes.zig"); +const Pardes = pardes.Pardes; + +/// The finder column's serial (layout.columnSerial); 0 while there is none. +serial: u32 = 0, +/// Its width, in thousandths of the window's: kept while it is closed, so +/// it comes back as wide as it went. +share: u16 = 300, + +/// More query panes than this and the oldest closes: each folded one keeps +/// a tag row. ponytail: a fixed count; size it from the column's rows. +pub const max_results = 8; + +const tag_text = "Finder Delcol"; + +/// The finder column's index, while it is there. +pub fn column(f: *const Finder, p: *const Pardes) ?usize { + if (f.serial == 0) return null; + return layout.columnBySerial(p, f.serial); +} + +/// Its width in cells: its share, leaving every other column MINW; the +/// whole window when it is the only column. +pub fn width(f: *const Finder, p: *const Pardes) u16 { + if (p.ncol <= 1) return p.screen_w; + const others: u32 = @as(u32, config.MINW) * @as(u32, @intCast(p.ncol - 1)); + const most: u32 = @as(u32, p.screen_w) -| others; + const wanted: u32 = @as(u32, p.screen_w) * f.share / 1000; + return @intCast(@min(@max(wanted, config.MINW), @max(most, @min(config.MINW, p.screen_w)))); +} + +/// Query pane `id` goes on top of the finder column, opened at the right +/// edge if there is none; the older ones fold. False when the window has +/// no room for the column (the caller attaches it instead). +pub fn place(f: *Finder, p: *Pardes, id: usize) bool { + const pane = p.panes[id] orelse return false; + const c = f.column(p) orelse f.open(p) orelse return false; + layout.insert(p, c, 0, id); + pane.vweight = 1; + pane.collapsed = false; + f.fold(p, c, id); + // The oldest goes once there are too many: the bottom one, as the top + // is always the newest. + while (p.col_n[c] > max_results) { + const oldest = p.col_panes[c][p.col_n[c] - 1]; + p.removePane(oldest, null) catch break; + } + return true; +} + +/// A finder column at the right edge, empty, its tag its own: the other +/// columns give it its share, each in proportion to its weight. Null when +/// the window has no room for one more column, or narrower columns would +/// leave a pane under its tag and 2 rows. +fn open(f: *Finder, p: *Pardes) ?usize { + if (p.ncol >= pardes.MAX_COLS or p.ncol == 0) return null; + if (p.screen_w < @as(u32, config.MINW) * @as(u32, @intCast(p.ncol + 1))) return null; + const c = p.ncol; + p.col_n[c] = 0; + // Not used for its width (layout.compute), only kept positive for the + // code that halves and joins weights. + p.col_weight[c] = layout.column_weight_unit; + p.col_tags[c] = .{ .what = .column, .gpa = p.gpa }; + p.col_tags[c].own = p.gpa.dupe(u8, tag_text) catch null; + p.col_serial[c] = 0; + p.ncol += 1; + f.serial = layout.columnSerial(p, c); + // A narrower column wraps long tags onto more rows: shared out again, + // and where that cannot hold every minimum there is no finder, as + // Newcol is refused. + layout.compute(p); + for (0..p.ncol) |k| if (k != c and !layout.columnAtMinimums(p, k) and !layout.shareColumn(p, k)) { + layout.dropColumnUnannounced(p, c); + f.serial = 0; + layout.compute(p); + return null; + }; + layout.noteColumn(p, "newcol", f.serial); + return c; +} + +/// Fold every pane of finder column `c` but `top` (and what is attached +/// to it, its +Preview) to its tag. +fn fold(f: *const Finder, p: *Pardes, c: usize, top: usize) void { + _ = f; + layout.compute(p); + for (p.col_panes[c][0..p.col_n[c]]) |k| { + const pane = p.panes[k] orelse continue; + if (k == top or layout.groupRoot(p, k) == top) { + pane.collapsed = false; + pane.vweight = 1; + } else if (!pane.collapsed) { + // As Collapse folds it: its weight keeps its height for later. + pane.vweight = @floatFromInt(@max(1, p.rects[k].h)); + pane.collapsed = true; + } + } + layout.compute(p); +} + +/// Query pane `id`, asked again: back on top of the stack, open, the rest +/// folded. Nothing outside the finder column moves. +pub fn raise(f: *Finder, p: *Pardes, id: usize) void { + const c = f.column(p) orelse return; + const at = layout.findPane(p, id) orelse return; + if (at.col != c) return; + if (at.idx != 0) { + // the pane and what is attached to it (its +Preview) move together + const end = layout.groupEnd(p, c, at.idx); + var moved: [pardes.MAX_PANES]usize = undefined; + const n = end - at.idx; + @memcpy(moved[0..n], p.col_panes[c][at.idx..end]); + for (moved[0..n]) |k| layout.removePane(p, k); + for (moved[0..n], 0..) |k, i| layout.insert(p, c, i, k); + } + f.fold(p, c, id); +} + +/// The column a pane asked for from the finder goes in (a row looked at, a +/// command run there): the column of the pane its query searches, else +/// the nearest other. Null when nothing points at the finder. +pub fn away(f: *Finder, p: *Pardes, from: usize, kind: pardes.exec.NewPane) ?usize { + const fc = f.column(p) orelse return null; + const in_finder = if (layout.findPane(p, from)) |at| at.col == fc else false; + const to_last = (kind == .command or kind == .errors) and fc == p.ncol - 1; + if (!in_finder and p.exec_column != fc and !to_last) return null; + if (in_finder) { + const root = layout.groupRoot(p, from); + if (p.panes[root]) |qp| if (qp.query) |q| if (p.paneBySerial(q.owner)) |oid| if (layout.findPane(p, oid)) |at| + if (at.col != fc) return at.col; + } + if (fc > 0) return fc - 1; + if (fc + 1 < p.ncol) return fc + 1; + // The finder is the only column: a document asked from it gets one of + // its own, left of it. + return layout.insertColumn(p, fc, true); +} + +/// The finder column has lost its last pane: it goes, and every other +/// column is as wide as before it came. +pub fn emptied(f: *Finder, p: *Pardes, c: usize) bool { + if (f.column(p) != c or p.col_n[c] != 0) return false; + layout.dropColumn(p, c); + f.serial = 0; + return true; +} + +/// A drag of the border between the finder column and column `other` +/// beside it: the finder's share follows the edge, and `other` takes the +/// difference, every other column keeping its width. +pub fn dragWidth(f: *Finder, p: *Pardes, other: usize, finder_w: u64) void { + const fc = f.column(p) orelse return; + if (p.screen_w == 0) return; + const combined: u64 = p.col_w[fc] + p.col_w[other]; + if (combined < 2 * @as(u64, config.MINW)) return; + const fw = std.math.clamp(finder_w, config.MINW, combined - config.MINW); + f.share = @intCast(@max(1, @min(999, fw * 1000 / p.screen_w))); + var rest_weight: u128 = 0; + var rest_cells: u64 = 0; + for (0..p.ncol) |k| if (k != fc and k != other) { + rest_weight += p.col_weight[k]; + rest_cells += p.col_w[k]; + }; + if (rest_cells > 0) { + const other_cells = combined - fw; + const w = @as(u128, other_cells) * rest_weight / rest_cells; + p.col_weight[other] = @intCast(std.math.clamp(w, 1, layout.max_column_weight)); + } + layout.compute(p); +} + +fn typeKeys(p: *Pardes, text: []const u8) void { + for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); +} + +test "SearchPlace column: query panes stack in a finder column at the right edge, nothing else moves after it opens, and it goes with its last pane" { + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); + defer p.deinit(); + p.settings.search_place = .column; + const pane = try p.setTestFile("alpha one\nbeta\nalphabet\n"); + p.newScratchBelow(0); + const other = p.active; + p.active = 0; + layout.compute(p); + const before = p.rects; + const width_before = p.col_w[0]; + typeKeys(p, "/"); + const fc = p.finder.column(p).?; + try std.testing.expectEqual(@as(usize, 1), fc); + const first = p.col_panes[fc][0]; + try std.testing.expect(p.panes[first].?.query != null); + // the first search narrows the column once; its panes keep their rows + try std.testing.expect(p.col_w[0] < width_before); + try std.testing.expectEqual(before[0].h, p.rects[0].h); + try std.testing.expectEqual(before[other].h, p.rects[other].h); + typeKeys(p, "alpha"); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expect(pane.places.started); + layout.compute(p); + const opened = p.rects; + // a second search, from the other pane: on top, the first folded + p.active = other; + typeKeys(p, "/"); + const second = p.col_panes[fc][0]; + try std.testing.expect(second != first); + try std.testing.expect(p.panes[first].?.collapsed); + layout.compute(p); + try std.testing.expectEqualDeep(opened[0], p.rects[0]); + try std.testing.expectEqualDeep(opened[other], p.rects[other]); + // Esc: the second closes, the first stays + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.panes[second] == null); + try std.testing.expectEqual(fc, p.finder.column(p).?); + // the first's Del: the column goes, every other as wide as before it + pardes.exec.runBuiltin(p, .Del, first, "", null); + try std.testing.expect(p.finder.column(p) == null); + layout.compute(p); + try std.testing.expectEqual(width_before, p.col_w[0]); + try std.testing.expectEqualDeep(before[0], p.rects[0]); +} -- cgit v1.3 From 96f840a055651b88eb1191772bc4b10fcbbb60ce Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 28 Oct 2026 17:56:30 -0300 Subject: 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 --- src/Finder.zig | 13 +++++++---- src/exec.zig | 47 ++++++++++++++++++++++---------------- src/layout.zig | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/pardes.zig | 65 +++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 159 insertions(+), 38 deletions(-) (limited to 'src/Finder.zig') diff --git a/src/Finder.zig b/src/Finder.zig index a2b8f89f..e72a8dab 100644 --- a/src/Finder.zig +++ b/src/Finder.zig @@ -73,6 +73,8 @@ pub fn place(f: *Finder, p: *Pardes, id: usize) bool { fn open(f: *Finder, p: *Pardes) ?usize { if (p.ncol >= pardes.MAX_COLS or p.ncol == 0) return null; if (p.screen_w < @as(u32, config.MINW) * @as(u32, @intCast(p.ncol + 1))) return null; + const before_min = layout.minima(p); + const before = p.rects; const c = p.ncol; p.col_n[c] = 0; // Not used for its width (layout.compute), only kept positive for the @@ -83,11 +85,12 @@ fn open(f: *Finder, p: *Pardes) ?usize { p.col_serial[c] = 0; p.ncol += 1; f.serial = layout.columnSerial(p, c); - // A narrower column wraps long tags onto more rows: shared out again, - // and where that cannot hold every minimum there is no finder, as - // Newcol is refused. - layout.compute(p); - for (0..p.ncol) |k| if (k != c and !layout.columnAtMinimums(p, k) and !layout.shareColumn(p, k)) { + // A narrower column wraps long tags onto more rows: those rows back + // from the panes with rows to spare, shared out again only where that + // is not enough, and where nothing holds every minimum there is no + // finder, as Newcol is refused. + layout.restoreMinimaFrom(p, &before, &before_min); + for (0..p.ncol) |k| if (k != c and layout.squeezed(p, k, &before, &before_min) and !layout.shareColumn(p, k)) { layout.dropColumnUnannounced(p, c); f.serial = 0; layout.compute(p); diff --git a/src/exec.zig b/src/exec.zig index 5b0eb204..c14a648c 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -457,12 +457,9 @@ fn spawnTtyWithMount(p: *Pardes, from: usize, v9fs: bool) ?*Pane { fn refusedPlacement(p: *Pardes, id: usize) bool { if (!p.unplaced.isSet(id)) return false; p.unplaced.unset(id); + // It held no weight (placeNew put every pane's rows back as they + // were): nothing else moves, a pane dragged short included. p.removePane(id, null) catch {}; - // As sync does for a refused pane: none it squeezed stays under its - // minimum. - for (0..p.ncol) |c| if (!layout.columnAtMinimums(p, c)) { - _ = layout.shareColumn(p, c); - }; return true; } @@ -1208,6 +1205,7 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan const asked = if (p.exec_column != null) null else origin; layout.compute(p); const before = p.rects; + const before_min = layout.minima(p); switch (p.settings.placement) { .acme => switch (kind) { // New: the bottom half of the last pane in its own column @@ -1233,17 +1231,22 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan for (p.col_panes[f.col][0..p.col_n[f.col]]) |k| p.rects[k] = before[k]; layout.snapColWeights(p, f.col); if (!layout.splitTallest(p, f.col, id) or !layout.placedRoomy(p, id, &before)) { - if (layout.findPane(p, id) == null) layout.insert(p, f.col, p.col_n[f.col], id); - // No pane to halve, but the column holds every pane's minimum - // with the new one's: the rows are shared out again, so what is - // refused is only what the documented arithmetic cannot hold. + if (layout.findPane(p, id) != null) { + layout.removePane(p, id); + for (p.col_panes[f.col][0..p.col_n[f.col]]) |k| p.rects[k] = before[k]; + layout.snapColWeights(p, f.col); + } + // No pane to halve, but the column has the rows for the new + // one's minimum above the others': it takes them from those with + // the most to spare (a pane dragged short keeps its own), so + // what is refused is only what the documented arithmetic cannot + // hold. // +Errors and 9P's pane/new go wherever there is room, last // column first, as acme takes rows from a window that has them // before saying there are none; with none, +Errors's maker says // the text some other way (appendErrors), and pane/new is // refused. - if (layout.shareColumn(p, f.col)) {} else if (kind == .errors or kind == .fs) { - layout.removePane(p, id); + if (layout.takeRoom(p, f.col, id)) {} else if (kind == .errors or kind == .fs) { var c = p.ncol; while (c > 0) { c -= 1; @@ -1259,14 +1262,15 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan } else { layout.insert(p, f.col, p.col_n[f.col], id); p.unplaced.set(id); + // Refused holding no weight: its column's rows come + // back as they were. + p.panes[id].?.vweight = 0; // No pane anywhere can give it rows: pane/new is refused. - if (kind == .fs) { - p.panes[id].?.vweight = 0; - p.reportError(from, "placement", error.NoPaneRoom); - } + if (kind == .fs) p.reportError(from, "placement", error.NoPaneRoom); return; } } else { + layout.insert(p, f.col, p.col_n[f.col], id); // Refused, it closes at the step's end holding no weight, so // its column's rows come back as they were, none rounded off. p.panes[id].?.vweight = 0; @@ -1276,11 +1280,14 @@ pub fn placeNew(p: *Pardes, from: usize, origin: ?usize, id: usize, kind: NewPan } } }; - // Placed: no pane of its column left under its minimum by the rows - // rounding or an earlier placement gave it; shared out again if so. - if (layout.findPane(p, id)) |f| if (!layout.columnAtMinimums(p, f.col)) { - _ = layout.shareColumn(p, f.col); - }; + // Placed: no pane the rows' rounding took under its minimum stays + // there. Only those: a pane dragged short before keeps its rows, and + // the others keep theirs, as acme's coladd moves only the window it + // splits (cols.c:41-108). The new pane had nothing to keep: it is + // lifted to its minimum too. + var settled = before; + settled[id].h = std.math.maxInt(u16); + layout.restoreMinimaFrom(p, &settled, &before_min); if (kind == .command) return; tagline.exitHeader(p); p.active = id; diff --git a/src/layout.zig b/src/layout.zig index efa79394..f545f60d 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -681,6 +681,24 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { /// from whichever pane of its column has the most above its own. A pane /// dragged short before keeps what it had. pub fn restoreMinima(p: *Pardes, before: *const [MAX_PANES]Rect) void { + restoreMinimaFrom(p, before, null); +} + +/// Each pane's `minRows` now: what `restoreMinimaFrom` measures a step that +/// grows the minima (a narrower column wrapping tags) against. +pub fn minima(p: *Pardes) [MAX_PANES]u16 { + compute(p); + var mins: [MAX_PANES]u16 = @splat(0); + for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |k| { + mins[k] = minRows(p, k); + }; + return mins; +} + +/// restoreMinima, a pane's minimum before the step `before_min` (its tag +/// may wrap onto more rows since): one that had that minimum is lifted to +/// its minimum now, one dragged under it before keeps its rows. +pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void { compute(p); for (0..p.ncol) |c| { const n = p.col_n[c]; @@ -693,11 +711,11 @@ pub fn restoreMinima(p: *Pardes, before: *const [MAX_PANES]Rect) void { if (pane.collapsed) break; hs[i] = p.rects[k].h; mins[i] = minRows(p, k); - if (hs[i] < mins[i] and before[k].h >= mins[i]) short = true; + if (hs[i] < mins[i] and before[k].h >= if (before_min) |bm| bm[k] else mins[i]) short = true; } else { if (!short) continue; for (p.col_panes[c][0..n], 0..) |k, i| { - if (hs[i] >= mins[i] or before[k].h < mins[i]) continue; + if (hs[i] >= mins[i] or before[k].h < if (before_min) |bm| bm[k] else mins[i]) continue; while (hs[i] < mins[i]) { var giver: ?usize = null; var spare: u16 = 0; @@ -716,6 +734,53 @@ pub fn restoreMinima(p: *Pardes, before: *const [MAX_PANES]Rect) void { compute(p); } +/// Whether a pane of column `c` is under its minimum now that had its +/// minimum then (`before`, `before_min`): one a step squeezed, not one +/// dragged short. +pub fn squeezed(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_min: *const [MAX_PANES]u16) bool { + compute(p); + if (p.col_n[c] < 2) return false; + for (p.col_panes[c][0..p.col_n[c]]) |k| { + const pane = p.panes[k] orelse continue; + if (!pane.collapsed and p.rects[k].h < minRows(p, k) and before[k].h >= before_min[k]) return true; + } + return false; +} + +/// Column `c`'s rows for `id`, last in it, at its minimum: a row at a +/// time from whichever pane has the most above its own minimum, so a pane +/// dragged short keeps its rows and the others give only what they must. +/// False, changing nothing, when the column has not the rows. +pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { + compute(p); + const n = p.col_n[c]; + p.rects[id].w = p.col_w[c]; + var need = minRows(p, id); + var hs: [MAX_PANES]u16 = undefined; + var mins: [MAX_PANES]u16 = undefined; + var spare: u32 = 0; + for (p.col_panes[c][0..n], 0..) |k, i| { + const pane = p.panes[k] orelse return false; + if (pane.collapsed) return false; + hs[i] = p.rects[k].h; + mins[i] = minRows(p, k); + spare += hs[i] -| mins[i]; + } + if (spare < need) return false; + while (need > 0) : (need -= 1) { + var giver: usize = 0; + for (1..n) |i| if (hs[i] -| mins[i] > hs[giver] -| mins[giver]) { + giver = i; + }; + hs[giver] -= 1; + } + for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); + insert(p, c, n, id); + p.panes[id].?.vweight = @floatFromInt(minRows(p, id)); + compute(p); + return true; +} + /// After placing `id`: whether it, and every pane of its column that the /// placement shrank, still has its tag and `min_body_rows` (from `before`, /// the rects as they were). A pane alone in its column always has room: the @@ -908,6 +973,9 @@ pub fn snapColWeights(p: *Pardes, c: usize) void { pub fn absorbVWeight(p: *Pardes, id: usize, to: ?usize) ?usize { const f = findPane(p, id) orelse return null; if (p.col_n[f.col] <= 1) return null; + // A refused pane held no weight: the rows the others' rounding lent it + // go back to them as they were, nobody's weight snapped. + if (p.panes[id]) |pane| if (!pane.collapsed and pane.vweight == 0) return null; snapColWeights(p, f.col); var sib = to orelse if (f.idx > 0) p.col_panes[f.col][f.idx - 1] else p.col_panes[f.col][f.idx + 1]; var k = f.idx; 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); -- cgit v1.3