diff options
| -rw-r--r-- | src/Query.zig | 4 | ||||
| -rw-r--r-- | src/layout.zig | 47 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 2 |
3 files changed, 20 insertions, 33 deletions
diff --git a/src/Query.zig b/src/Query.zig index 6a0d43bb..a0ccd0e5 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -318,10 +318,10 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize if (p.settings.search_place == .column) { // On top of the finder column at the right edge (Finder.zig), the // older query panes folded under it; its preview under it there. - if (!p.finder.place(p, free) and !layout.attach(p, owner_id, free, want)) exec.placeNew(p, owner_id, owner_id, free, .doc); + if (!p.finder.place(p, free) and !layout.attachFrom(p, owner_id, free, want, owner_id)) exec.placeNew(p, owner_id, owner_id, free, .doc); if (with_preview) _ = makePreview(p, free, p.rects[free].h / 2, free); return free; - } else if (!layout.attach(p, owner_id, free, want)) { + } else if (!layout.attachFrom(p, owner_id, free, want, owner_id)) { // An owner too short to give a query pane its rows: placed as any // new pane is, the one place a search moves another pane. exec.placeNew(p, owner_id, owner_id, free, .doc); diff --git a/src/layout.zig b/src/layout.zig index 91947997..46db6439 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -239,11 +239,8 @@ pub fn targetColumn(p: *Pardes, cur_x: u16) usize { return tc; } -pub fn splitRowForExtent(y: u16, h: u16, cur_y: u16) ?u16 { - return splitRowFor(y, h, cur_y, null); -} - -/// As `splitRowForExtent`, each pane keeping at least `least` rows when +/// The row that splits the `h` rows from `y` nearest `cur_y`, each side +/// keeping MINH rows when there are that many (else one), or `least` when /// given: a pane dragged by its grip within its own column is how a /// terminal resizes, and acme lets either window keep only its tag. fn splitRowFor(y: u16, h: u16, cur_y: u16, least: ?u16) ?u16 { @@ -667,14 +664,6 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { return true; } -/// After a resize the minima fit: each unfolded pane the resize took below -/// its `minRows` (it had them in `before`) gets them back, a row at a time -/// 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 { @@ -686,9 +675,12 @@ pub fn minima(p: *Pardes) [MAX_PANES]u16 { 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. +/// After a resize the minima fit: each unfolded pane the resize took below +/// its `minRows` (it had them in `before`) gets them back, a row at a time +/// from whichever pane of its column has the most above its own. A pane +/// dragged short before keeps what it had. With `before_min`, a pane's +/// minimum before the step (its tag may wrap onto more rows since): one +/// that had that minimum is lifted to its minimum now. pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void { compute(p); for (0..p.ncol) |c| { @@ -840,7 +832,7 @@ fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void { // Each keeps a tag and min_body_rows, where acme's minht keeps one. const lo = r.y +| minRows(p, v); const hi = (r.y + r.h) -| minRows(p, id); - const row = splitRowForExtent(r.y, r.h, if (lo <= hi) std.math.clamp(y, lo, hi) else r.y + r.h / 2) orelse { + const row = splitRowFor(r.y, r.h, if (lo <= hi) std.math.clamp(y, lo, hi) else r.y + r.h / 2, null) orelse { pane.vweight = BOX_H + 1; return; }; @@ -1089,14 +1081,9 @@ pub fn keepGroups(p: *Pardes) void { /// owner is unfolded first. The rows are the attachment's from then on: /// nothing here ever resizes it again; the seam is the user's to drag. /// False, `id` in no column, when the owner has not the rows for its tag -/// and the attachment's minimum. -pub fn attach(p: *Pardes, owner: usize, id: usize, rows: u16) bool { - return attachFrom(p, owner, id, rows, owner); -} - -/// attach, the rows given by `giver`: the owner itself or a pane of its -/// group (a +Preview added under a query pane later takes the text's rows, -/// so the query pane, typed into, keeps its own). +/// and the attachment's minimum. The rows are given by `giver`: the owner +/// itself or a pane of its group (a +Preview added under a query pane later +/// takes the text's rows, so the query pane, typed into, keeps its own). pub fn attachFrom(p: *Pardes, owner: usize, id: usize, rows: u16, giver: usize) bool { const o = p.panes[owner] orelse return false; const g = p.panes[giver] orelse return false; @@ -1648,7 +1635,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, // Under its owner, the rows asked for, the owner's and nobody else's. const s = try testAttachment(p); - try std.testing.expect(attach(p, 0, s, 9)); + try std.testing.expect(attachFrom(p, 0, s, 9, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); try std.testing.expectEqual(s, p.col_panes[0][1]); for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]); @@ -1657,7 +1644,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, try std.testing.expectEqual(@as(u16, 9), p.rects[s].h); // A second level (a preview under a query pane): out of the first's rows. const pv = try testAttachment(p); - try std.testing.expect(attach(p, s, pv, 4)); + try std.testing.expect(attachFrom(p, s, pv, 4, s)); try std.testing.expectEqual(pv, p.col_panes[0][2]); try std.testing.expectEqual(@as(usize, 0), groupRoot(p, pv)); try std.testing.expectEqual(@as(usize, 3), groupEnd(p, 0, 0)); @@ -1722,7 +1709,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, // Del of the owner closes what is attached to it. const again = try testAttachment(p); - try std.testing.expect(attach(p, 0, again, 6)); + try std.testing.expect(attachFrom(p, 0, again, 6, 0)); exec.runBuiltin(p, .Del, 0, "", null); try std.testing.expect(p.panes[0] == null and p.panes[again] == null); } @@ -1732,7 +1719,7 @@ test "an attachment survives Dump and Restore, and one left away from its owner defer p.deinit(); _ = try p.setTestFile("alpha\nbeta\nalphabet\n"); const s = try testAttachment(p); - try std.testing.expect(attach(p, 0, s, 8)); + try std.testing.expect(attachFrom(p, 0, s, 8, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); try dump.dumpState(p); const restored = try dump.initFromDump(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }, p.dump_out.?); @@ -1743,7 +1730,7 @@ test "an attachment survives Dump and Restore, and one left away from its owner try std.testing.expect(p.panes[s].?.attached_to == null); // Put above its owner by a route that does not carry groups: detached. const t = try testAttachment(p); - try std.testing.expect(attach(p, 0, t, 8)); + try std.testing.expect(attachFrom(p, 0, t, 8, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, t)); removePane(p, t); insert(p, 0, 0, t); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index aad2675c..0fb92b1a 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -754,7 +754,7 @@ pub fn writeRoot(p: *Pardes, req: Req) Reply { p.sync(); return refuseQuoting(p, req, "size: too small for the panes, each its tag and 2 rows", value, ""); } - pardes.layout.restoreMinima(p, &before); + pardes.layout.restoreMinimaFrom(p, &before, null); p.sync(); } continue; |
