summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 21:19:37 -0300
committerGabriel Schneider <[email protected]>2026-11-25 21:57:19 -0300
commit8e1526a71a74447cbba9f5487ef72d9feccfc0ed (patch)
treeca10fd5a4f2d2cffbb3a78299b4d6434395b56bf /core
parent1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e (diff)
downloadpardes-8e1526a71a74447cbba9f5487ef72d9feccfc0ed.tar.gz
pardes-8e1526a71a74447cbba9f5487ef72d9feccfc0ed.zip
Band, sync, draw, layout, mouse, File: the text stays put under the band: out of rest a tag keeps exactly its rows at rest, and its head's rows past them and the band under it are drawn over the top rows of its body, which never moves, wraps or resizes for them (UX DESIGN I1, on the user's "the other editors when there's new ui on top of the text it doesn't scroll ... I think we should do that, no?"); THE OLD WAY: the band pushed the body down (Pardes.sync grew `tag_rows` by `band_rows` and the head's rows), so every row of the text jumped by the band's height on SPC Down, Help, `:`, the registers, a rolled level of three rows, and back on Esc, while a terminal's and a kind's band was a second path drawn over its body (Band.over, Band.shownRows); THE CHANGE: Band.covered (from the state alone, as takes is) says where a tag out of rest is drawn: its head's rows, the band under them (as many as the pane has; a picker's keeping D6's body under it), and `over`, those past the tag's own rows; sync keeps the tag's rows at rest (the terminal special case is every pane's now) and puts `over` in the pane's view (SessionView.covered) for File.show; draw.render draws the host's tag and band after every body, one path for every pane, the grip's column beside the covered rows on the tag's ground, a caret under them hidden until rest; layout.floorRows borrows for a level, Help, `:` or the registers only the rows its head and band need (a picker and code actions keep D6's 60 % / 6 rows; a terminal's and a kind's size stay their user's); mouse.bandPoint gives a covered row to the band (a head's row over the body: B2/B3 on its word as on the tag's first row, B1 nothing); File.show counts the covered rows like the context rows, so what a state shows (a prompt's current hit, C-r's) is put in the rows left visible, a target already there not moved; TagState's rolled level of a terminal takes its three rows too (over the pty, which keeps its size); `band_rows` goes from Pane and PaneView (the dump: SessionView.covered and Pick.previewed come); W1'S READING (I1 is silent on a landing near a file's top): a picker's preview starts under its band (Pick.previewing: from the first place it shows in its landing pane, the band takes its rows from that body, as before), since Find lands on line 1 and a band over the body's top hid the file's first eleven lines and the landing line; before its first row, and after Esc, the pane's own text is where it was; the GUI's tag rule goes under the head's rows as under the band's (gui.zig paneDecor); TESTS (FIRST, where the old behaviour was asserted, inverted): Band.zig "SPC Down unrolls ... drawn over the top rows of the body, which stays where it was" (was "the body pushed down and never drawn over"), "out of rest the body stays where it was ..." (a rolled level, SPC Down, Help, `:`, the registers and a picker before it previews: every row of text under the rows drawn over it on its screen row at rest, the same first row, size and scroll; Esc leaves the body's rows as at rest), "a level's band covers what it needs ..." (no borrow where head and band fit, exactly head + band where they do not), "a covered row belongs to the band ..." (B1 on a band row over the body moves the level's cursor, on a head's row over it touches no body); Pick.zig "a picker's preview starts under its band ..." (in a reading pane: its text stays before the first row; line 60 at ⌈visible/3⌉ under the band, line 1 on the row right under it; Esc: its own text where it was); Prompt.zig "a search's current hit under C-r's band is put in the rows the band leaves the body ..."; the tests that read `band_rows` read Band.covered; body_layer's D10 test: `g`'s first-line target is under the rolled level's rows now (I2's named cost); GOLDENS re-recorded, every moved row: leader (spc, unmapped: the one line of cmds.txt stays on row 3 under the level's second row instead of row 5, the caret on it hidden), find (nomatch, topbar: a picker with nothing to preview leaves here.txt's line 1 on row 3 under the band instead of row 8; cancel: row 8 no longer listed as changed), ttyhelp (leaderworks: Help's band over the +Help pane's text, whose rows 10-20 keep the previous snap's text instead of moving down seven rows); a user saw the text jump on every SPC Down, Help, `:` with rows, registers Down and a rolled level wider than its tag; core-test 1115/1287 (172 skipped: +3), shell-test 1335/1338 (3 skipped: +3), pane-test 183/184, behaviour-test 280/280 and --replay 20 seeds 0 failures, process-test 0 of 147 failed (3 skipped; 3 goldens re-recorded), term-test 17/17, kitty-test 45/45; the dump fuzz at 40,000 join seeds and 40,000 + 1,779 image seeds 11/11; the soak `replicas -- --clients 5 --rtt 30,80,207`: diverged 0, unequal 0, quiet checks 580/0 480/0 675/0, unlisted stops 0, the corpus 22 of 22 scenes the same, no leak; load 1.2 to 10.9
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig251
-rw-r--r--core/Core.zig35
-rw-r--r--core/File.zig33
-rw-r--r--core/Pick.zig92
-rw-r--r--core/Prompt.zig42
-rw-r--r--core/TagState.zig38
-rw-r--r--core/Trail.zig10
-rw-r--r--core/bindings.zig2
-rw-r--r--core/body_layer.zig6
-rw-r--r--core/draw.zig72
-rw-r--r--core/layout.zig24
-rw-r--r--core/mouse.zig41
-rw-r--r--core/panes.zig19
-rw-r--r--core/views.zig33
14 files changed, 506 insertions, 192 deletions
diff --git a/core/Band.zig b/core/Band.zig
index cd4ca75b..8ee5c9f0 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -1,13 +1,14 @@
//! The band (walk UI, pick-ui SPEC.md §3.6): rows hanging under a pane's
-//! tag while it is out of rest, in the tag's tint, pushing its body down:
-//! the tag unrolled. Its steps stand side by side, each a column of rows
+//! tag while it is out of rest, in the tag's tint, drawn over the top rows
+//! of its body, which stay where they were (UX DESIGN I1): the tag
+//! unrolled. Its steps stand side by side, each a column of rows
//! (a level, Help's rows, a doc; later a picker's acts and sources, a
//! prompt's history, the registers), a one-cell rule between them, right
//! of a spine under each of the head's key cells.
//!
//! Derived from the live view's state each time it is asked (`of`), never
//! stored (the coordinator's R2): the layout reads its height (`takes`,
-//! Pardes.sync, layout.floorRows), the frame paints it (draw.zig
+//! `covered`, layout.floorRows), the frame paints it (draw.zig
//! joinBand) as a tag layer of kind `.band`, and the mouse reads its words
//! (`line`): read-only text, which B2 executes and B3 looks at as a tag's.
//!
@@ -131,20 +132,24 @@ pub fn takes(p: *Pardes, id: usize) u16 {
return @max(doc_rows, levelRows(n));
}
-/// A terminal's and a kind's band is drawn over the top rows of its body
-/// (UX D6's borrowing, R3: drawn, never written): a transient state never
-/// resizes a pty under a program or a kind's view (a PDF's), whose size
-/// only the user's resize changes. Their `band_rows` stay 0.
-pub fn over(pane: *const Pane) bool {
- return pane.isTerminal() or pane.addon != null;
-}
-
-/// The rows pane `id`'s band is drawn on: those it takes from the layout,
-/// or over a terminal's or a kind's body, as many of its body rows as the
-/// band wants.
-pub fn shownRows(p: *Pardes, pane: *const Pane, id: usize) u16 {
- if (pane.band_rows > 0 or !over(pane) or pane.collapsed) return pane.band_rows;
- return @min(takes(p, id), p.view().rects[id].h -| pane.tag_rows);
+/// Where pane `id`'s tag out of rest is drawn, in rows from its top (UX
+/// DESIGN I1): its head's text (`text`, the rows its own text keeps from
+/// rest at least where no band hangs under it) and the band under that
+/// (`band`), as many as the pane has; `over` of them past the tag's own
+/// rows (`tag_rows`, its rows at rest), drawn over the top rows of its
+/// body, which never move for them. A picker's band keeps a body of
+/// `body_rows` under it (UX D6), any other state only the pane's rows.
+/// Asked of the state alone, as `takes` is: the layout, the frame and a
+/// click ask it of the same step.
+pub const Covered = struct { text: u16, band: u16, over: u16 };
+pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered {
+ if (pane.collapsed or TagState.hostOf(p) != id) return .{ .text = pane.tag_rows, .band = 0, .over = 0 };
+ const h = p.view().rects[id].h;
+ const text = @min(layout.headRows(p, id), h);
+ const keep: u16 = if (p.view().tag_state.kind == .pick) body_rows else 0;
+ const band = @min(takes(p, id), h -| text -| keep);
+ const shown = if (band > 0) text else @min(@max(text, pane.tag_rows), pardes.MAX_TAG_ROWS);
+ return .{ .text = shown, .band = band, .over = (shown + band) -| pane.tag_rows };
}
fn levelRows(n: u16) u16 {
@@ -696,8 +701,10 @@ test "a narrow band gives way and keeps its spines: the doc goes, the steps star
const s = try p.render(a);
const r = p.view().rects[id];
const tag_y = p.tagTop(pane, r);
- try std.testing.expectEqual(@as(u16, 1), pane.tag_rows - pane.band_rows);
- try std.testing.expectEqual(@max(rest, 1 + band.height), pane.tag_rows);
+ const at = covered(p, pane, id);
+ try std.testing.expectEqual(@as(u16, 1), at.text);
+ try std.testing.expectEqual(rest, pane.tag_rows);
+ try std.testing.expectEqual((1 + band.height) -| rest, at.over);
try std.testing.expectEqual(tag_y + 1, bandLayer(p, id).?.viewport.y);
for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + 1).grapheme());
try std.testing.expect(std.mem.indexOf(u8, try layerRow(a, bandLayer(p, id).?, 0), "▶") != null);
@@ -715,7 +722,7 @@ test "out of rest with no band, the rows a tag keeps from rest stay blank: a spi
// A search prompt: a key cell in its head, no band under it.
p.update(.{ .key = .{ .cp = '/', .text = "/" } });
p.sync();
- try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+ try std.testing.expectEqual(@as(u16, 0), covered(p, pane, id).band);
try std.testing.expectEqual(rest, pane.tag_rows);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
@@ -828,7 +835,7 @@ test "a row longer than its room is cut with `…`: a path from the left, anythi
try std.testing.expectEqualStrings("short", fits.text);
}
-test "SPC Down unrolls the level into a band under the tag's text, the body pushed down and never drawn over; Up on its first row rolls it up" {
+test "SPC Down unrolls the level into a band under the tag's text, drawn over the top rows of the body, which stays where it was (UX DESIGN I1); Up on its first row rolls it up" {
const Key = pardes.Key;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
defer p.deinit();
@@ -840,30 +847,40 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push
const r = p.view().rects[id];
const text_rows = pane.tag_rows;
const body_top = p.bodyTop(pane, r);
+ const rows = pane.rows;
_ = try p.render(frame.allocator());
try std.testing.expect(bandLayer(p, id) == null);
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = Key.down } });
try std.testing.expect(p.view().tag_state.unrolled);
// SPC's top has more than nine children: two columns, and a doc.
- try std.testing.expect(pane.band_rows >= doc_rows);
- try std.testing.expectEqual(text_rows + pane.band_rows, pane.tag_rows);
- try std.testing.expectEqual(body_top + pane.band_rows, p.bodyTop(pane, r));
+ const at = covered(p, pane, id);
+ try std.testing.expect(at.band >= doc_rows);
+ try std.testing.expect(at.over > 0);
+ // The tag keeps its rows at rest, the body its first row and its size.
+ try std.testing.expectEqual(text_rows, pane.tag_rows);
+ try std.testing.expectEqual(body_top, p.bodyTop(pane, r));
+ try std.testing.expectEqual(rows, pane.rows);
+ try std.testing.expectEqual(at.over, pane.view.covered);
_ = frame.reset(.retain_capacity);
const s = try p.render(frame.allocator());
const layer = bandLayer(p, id).?;
- try std.testing.expectEqual(p.tagTop(pane, r) + text_rows, layer.viewport.y);
- try std.testing.expectEqual(pane.band_rows, layer.viewport.h);
- // The body region starts under the band: nothing is drawn over it.
+ try std.testing.expectEqual(p.tagTop(pane, r) + at.text, layer.viewport.y);
+ try std.testing.expectEqual(at.band, layer.viewport.h);
+ // The body region starts where it did at rest: the band is over it.
const body = s.region(.body, id).?;
- try std.testing.expectEqual(layer.viewport.y + layer.viewport.h, body.rect.y);
+ try std.testing.expectEqual(body_top, body.rect.y);
+ try std.testing.expect(layer.viewport.y + layer.viewport.h > body.rect.y);
const first = try layerRow(frame.allocator(), layer, 0);
try std.testing.expect(std.mem.indexOf(u8, first, "│") != null);
try std.testing.expect(std.mem.indexOf(u8, first, "▶ b buffer…") != null);
- // The grid has the same row, where the layer is.
+ // The grid has the same rows, where the layer is, the body's under
+ // them drawn first: its last covered row is the band's.
var grid: std.ArrayList(u8) = .empty;
for (s.cells[@as(usize, layer.viewport.y) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme());
try std.testing.expect(std.mem.indexOf(u8, grid.items, "▶ b buffer…") != null);
+ const spine = (try of(p, frame.allocator(), pane, id)).?.spines[0];
+ try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + spine, layer.viewport.y + layer.viewport.h - 1).grapheme());
// The head names the level and says how to roll it up.
const head = try tagline.tagText(p, frame.allocator(), pane);
try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ↑ roll up · ? field · esc"));
@@ -874,7 +891,7 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push
try std.testing.expect(p.view().tag_state.unrolled);
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expect(!p.view().tag_state.unrolled);
- try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+ try std.testing.expectEqual(@as(u16, 0), covered(p, pane, id).band);
try std.testing.expectEqual(body_top, p.bodyTop(pane, r));
// Unrolled, Right enters the cursor's group and Left leaves it.
p.update(.{ .key = .{ .cp = Key.down } });
@@ -884,13 +901,14 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push
p.update(.{ .key = .{ .cp = Key.left } });
try std.testing.expectEqual(@as(u8, 0), p.view().leader_n);
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+ try std.testing.expectEqual(@as(u16, 0), covered(p, pane, id).band);
+ try std.testing.expectEqual(@as(u16, 0), pane.view.covered);
try std.testing.expect(!p.view().tag_state.unrolled);
}
-test "a band keeps its pane's body 60 % of the pane, borrowed from its column; where the column has not the rows, the band gives way before the body drops under 6" {
+test "a level's band covers what it needs: its pane keeps its rows where its head and band fit, and borrows from its column only the rows they need where they do not (UX DESIGN I1)" {
const Key = pardes.Key;
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 60 });
defer p.deinit();
_ = try p.setTestFile("one\n");
const top = p.view().active;
@@ -899,42 +917,25 @@ test "a band keeps its pane's body 60 % of the pane, borrowed from its column; w
p.newScratchBelow(low);
p.view().active = low;
p.sync();
+ const before = p.view().rects;
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = Key.down } });
const pane = p.panes[low].?;
- const r = p.view().rects[low];
- try std.testing.expect(pane.band_rows >= doc_rows);
- try std.testing.expect(@as(u32, r.h -| pane.tag_rows) * 5 >= @as(u32, r.h) * 3);
+ const at = covered(p, pane, low);
+ const need = at.text + at.band;
+ try std.testing.expect(at.band == takes(p, low) and need <= before[low].h);
+ try std.testing.expectEqualDeep(before, p.view().rects);
p.update(.{ .key = .{ .cp = Key.escape } });
- // A window of 12 rows: the band shrinks, the body keeps 6.
- p.update(.{ .resize = .{ .cols = 120, .rows = 12 } });
+ // A window of 24 rows: seven a pane, the head and band need more.
+ p.update(.{ .resize = .{ .cols = 120, .rows = 24 } });
+ const short = p.view().rects[low].h;
+ try std.testing.expect(short < need);
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = Key.down } });
- p.sync();
- const short = p.view().rects[low];
- try std.testing.expect(short.h -| pane.tag_rows >= 6 or pane.band_rows == 0);
- try std.testing.expect(pane.band_rows < Band.takes(p, low));
-}
-
-test "a pane whose body would drop below six rows under its band borrows them from its column" {
- const Key = pardes.Key;
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 });
- defer p.deinit();
- _ = try p.setTestFile("one\n");
- const top = p.view().active;
- p.newScratchBelow(top);
- const low = p.view().active;
- p.newScratchBelow(low);
- p.view().active = low;
- p.sync();
- const before = p.view().rects[low].h;
- p.update(.{ .key = .{ .cp = ' ' } });
- p.update(.{ .key = .{ .cp = Key.down } });
- const pane = p.panes[low].?;
const r = p.view().rects[low];
- try std.testing.expect(r.h > before);
- // Its body six rows at least (UX D6): a column too short for 60 %.
- try std.testing.expect(r.h -| pane.tag_rows >= 6);
+ const grown = covered(p, pane, low);
+ try std.testing.expectEqual(need, r.h);
+ try std.testing.expectEqual(at, grown);
// No pane dims out of rest (UX D9): the others look as at rest.
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
@@ -944,7 +945,7 @@ test "a pane whose body would drop below six rows under its band borrows them fr
try std.testing.expect(!s.at(other.x + 3, other.y + 1).style.dim);
try std.testing.expect(!s.at(r.x + 3, r.y).style.dim);
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(before, p.view().rects[low].h);
+ try std.testing.expectEqual(short, p.view().rects[low].h);
}
test "the band's words are read-only text: B2 runs one, the tag back at rest" {
@@ -1114,3 +1115,127 @@ test "an empty level gives no rows: SPC unrolled on an addon's group, or describ
_ = try p.render(a);
}
}
+
+test "out of rest the body stays where it was: under a rolled level, SPC Down, Help, `:`, the registers and a picker that has not previewed, every row of its text on the screen row it had at rest, its first row and its size the same; Esc leaves the body's rows as at rest (UX DESIGN I1)" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (1..121) |i| try text.print(gpa, "line {d} of the text\n", .{i});
+ const pane = try p.setTestFile(text.items);
+ const id = p.view().active;
+ pane.focus = .body;
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ // Into the text: the view scrolled, the caret on a row under the top.
+ for ("60jk") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ const r = p.view().rects[id];
+ const body_top = p.bodyTop(pane, r);
+ const tag_rows, const rows, const top = .{ pane.tag_rows, pane.rows, pane.file.?.scroll };
+ try std.testing.expect(top > 0);
+ const rest = try gpa.dupe(pardes.Cell, (try p.render(frame.allocator())).cells);
+ defer gpa.free(rest);
+ const cols = p.surface.cols;
+ const list = try std.fmt.allocPrint(gpa, "{s}:3:1 line 3 of the text\n", .{pane.file.?.path});
+ defer gpa.free(list);
+ for ([_][]const u8{ "rolled", "unrolled", "help", "colon", "registers", "picker" }) |state| {
+ if (std.mem.eql(u8, state, "picker")) {
+ pardes.Pick.open(p, id, .list, "Refs", "", list);
+ } else {
+ const keys: []const Key = if (std.mem.eql(u8, state, "rolled")) &.{.{ .cp = ' ' }} else if (std.mem.eql(u8, state, "unrolled")) &.{ .{ .cp = ' ' }, .{ .cp = Key.down } } else if (std.mem.eql(u8, state, "help")) &.{ .{ .cp = ' ' }, .{ .cp = '?' } } else if (std.mem.eql(u8, state, "colon")) &.{.{ .cp = ':' }} else &.{ .{ .cp = '"' }, .{ .cp = Key.down } };
+ for (keys) |k| p.update(.{ .key = k });
+ // A rolled level shows after its delay.
+ p.advance(p.clock.now_ns);
+ if (p.view().tag_state.due_ns > p.clock.now_ns) p.clock.now_ns = p.view().tag_state.due_ns;
+ }
+ p.sync();
+ errdefer std.debug.print("state {s}\n", .{state});
+ try std.testing.expect(TagState.hostOf(p) == id);
+ const at = covered(p, pane, id);
+ try std.testing.expect(at.over > 0);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ try std.testing.expectEqual(top, pane.file.?.scroll);
+ try std.testing.expectEqual(body_top, p.bodyTop(pane, r));
+ _ = frame.reset(.retain_capacity);
+ const s = try p.render(frame.allocator());
+ // Under the rows drawn over it, the body's text on its rows.
+ var y = body_top + at.over;
+ while (y < r.y + r.h) : (y += 1) for (r.x + pardes.config.GUTTER..r.x + r.w) |x| {
+ const i = @as(usize, y) * cols + x;
+ try std.testing.expectEqualStrings(rest[i].grapheme(), s.cells[i].grapheme());
+ };
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ p.sync();
+ try std.testing.expect(TagState.hostOf(p) == null);
+ _ = frame.reset(.retain_capacity);
+ const back = try p.render(frame.allocator());
+ y = body_top;
+ while (y < r.y + r.h) : (y += 1) for (r.x..r.x + r.w) |x| {
+ const i = @as(usize, y) * cols + x;
+ try std.testing.expect(std.meta.eql(rest[i], back.cells[i]));
+ };
+ }
+}
+
+test "a covered row belongs to the band: a click on a band row over the body moves the band's cursor, on the head's row over it runs or looks at its word, never the body under them (UX DESIGN I1)" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (1..61) |i| try text.print(gpa, "line {d} of the text\n", .{i});
+ const pane = try p.setTestFile(text.items);
+ const id = p.view().active;
+ pane.focus = .body;
+ p.sync();
+ const r = p.view().rects[id];
+ const body_top = p.bodyTop(pane, r);
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = Key.down } });
+ const at = covered(p, pane, id);
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ const band = (try of(p, frame.allocator(), pane, id)).?;
+ // The band's last row, over the body: its first step's row there.
+ const row: u16 = at.band - 1;
+ const y = p.tagTop(pane, r) + at.text + row;
+ try std.testing.expect(y >= body_top);
+ const ln = try band.line(frame.allocator(), p.settings.tab, row);
+ const part = ln.parts[0];
+ const x = r.x + pardes.TAG_TEXT_INSET + part.col + 1;
+ const caret = .{ pane.body.cur_row, pane.body.cur_col };
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = y } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = y } });
+ var children: [bindings.max_children]bindings.Child = undefined;
+ try std.testing.expectEqual(bindings.level(p, .leader, "", &children)[part.row.index].key, p.view().tag_state.hi);
+ try std.testing.expect(p.view().tag_state.unrolled);
+ try std.testing.expectEqual(caret, .{ pane.body.cur_row, pane.body.cur_col });
+ try std.testing.expectEqual(pardes.Pane.Focus.body, pane.focus);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // SPC's rolled level, rows over the body under its first: a click on
+ // one is the head's, not the body's (B1 there does nothing).
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ const rolled = covered(p, pane, id);
+ try std.testing.expect(rolled.band == 0 and rolled.text > pane.tag_rows);
+ const hy = p.tagTop(pane, r) + rolled.text - 1;
+ try std.testing.expect(hy >= body_top);
+ const hx = r.x + pardes.TAG_TEXT_INSET + 6;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = hx, .row = hy } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = hx, .row = hy } });
+ try std.testing.expect(TagState.hostOf(p) == id);
+ try std.testing.expectEqual(caret, .{ pane.body.cur_row, pane.body.cur_col });
+ try std.testing.expectEqual(pardes.Pane.Focus.body, pane.focus);
+}
diff --git a/core/Core.zig b/core/Core.zig
index 8c946787..39e04f62 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -2049,36 +2049,27 @@ pub fn sync(p: *Pardes) void {
caret_row = std.mem.count(u8, shown.text[0..@min(shown.fromReal(cur), shown.text.len)], "\n");
}
if (!pane.tag_expanded) wanted = 1;
- // Out of rest the head is the tag's text (TagState), and the tag
- // keeps the rows its own text takes at rest at least: a head shorter
- // than it (a root's key cell, before its level shows) moved the body
- // up and back down a moment later; a terminal's exactly those, its
- // pty its body (a resize the program under it saw at every C-w and
- // SPC). A band takes the kept rows first (below).
- var kept: usize = 0;
- if (pardes.TagState.hostOf(p) == id and !pane.collapsed) {
- kept = layout.wantedTagRows(p, id);
- if (pane.isTerminal()) wanted = kept;
- }
+ // Out of rest the tag keeps exactly the rows its own text takes at
+ // rest: its head's rows past them and the band under it are drawn
+ // over the top rows of its body, which never move for them (UX
+ // DESIGN I1, Band.covered); its head is drawn whole from its first
+ // row. A picker's preview starts under them, as a file's first
+ // lines could not be put under a band otherwise (Pick.previewing).
+ const host = pardes.TagState.hostOf(p) == id and !pane.collapsed;
+ if (host) wanted = layout.wantedTagRows(p, id);
pane.tag_rows = @intCast(@min(wanted, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1)));
if (pane.collapsed) pane.tag_rows = BOX_H;
- if (pane.focus == .tag and pane.prompt != .name) {
+ if (pane.focus == .tag and pane.prompt != .name and !host) {
const cur: usize = caret_row;
var top: usize = pane.tag_top;
if (cur < top) top = cur;
if (cur >= top + pane.tag_rows) top = cur + 1 - pane.tag_rows;
pane.tag_top = @intCast(@min(top, lines -| pane.tag_rows));
} else pane.tag_top = 0;
- // The band unrolled under the head pushes the body down: the tag's
- // rows, as everything under them counts them. Its first row is the
- // one under the head's last, and the rows the tag keeps from rest
- // are its own (UX E3: never a blank row between a head and its
- // rows); with no band they stay the tag's, blank. A terminal's or
- // a kind's is drawn over its body instead (Band.over).
- const band = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows -| pardes.Band.body_rows);
- const keep: u16 = @intCast(@min(kept, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1)));
- pane.band_rows = if (band == 0) 0 else @max(band, keep -| pane.tag_rows);
- pane.tag_rows = @max(keep, pane.tag_rows + pane.band_rows);
+ const over = if (host) pardes.Band.covered(p, pane, id).over else 0;
+ const preview = host and pardes.Pick.previewing(p, id);
+ if (preview) pane.tag_rows += over;
+ pane.view.covered = if (preview) 0 else over;
const cols = @max(1, r.w -| config.GUTTER);
// The tag steals the top rows. The pty is what the pane shows
// (layout keeps a terminal two body rows where the window has
diff --git a/core/File.zig b/core/File.zig
index 41cc025f..0f9178ac 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -2059,6 +2059,22 @@ fn shownNow(pane: *const Pane) u16 {
return @max(1, if (pane.wrap_n == 0) pane.rows else visible -| pane.context_rows);
}
+/// The rows of `pane`'s map its tag out of rest draws over (UX DESIGN I1,
+/// `view.covered` grid rows from the body's top): its context rows at the
+/// tagline's height where the geometry stacks them so, the rest at the
+/// body's.
+pub fn coveredRows(pane: *const Pane) u16 {
+ const v = pane.view;
+ if (v.covered == 0) return 0;
+ const bh: usize = @max(1, v.body_h);
+ const th: usize = std.math.clamp(v.tagline_h, 1, bh);
+ const px = @as(usize, v.covered) * bh;
+ const compact: usize = if (pane.context_row_limit != null) pane.context_rows else 0;
+ const rows = if (compact * th >= px) (px + th - 1) / th else compact + (px - compact * th + bh - 1) / bh;
+ // A damaged dump's covered rows are any: never past a u16's.
+ return @intCast(@min(rows, std.math.maxInt(u16)));
+}
+
/// The view moved when line `line_at`'s row that shows its byte `col` is
/// out of the body's margins (`margin_rows` rows, helix's scrolloff, at
/// most half of it): by the rows that show the line's rows whole inside
@@ -2068,17 +2084,22 @@ pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) voi
const f = &pane.file.?;
geometry(tab, pane);
const t = topNow(tab, pane);
+ // Its rows a tag out of rest draws over (UX DESIGN I1): what a state
+ // shows goes under them, as under the context rows; the bottom stays.
+ const covered: u16 = coveredRows(pane);
+ const hidden: i64 = covered -| pane.context_rows;
// The line held at the top (a sticky context row): as it is.
if (pane.context_rows < pane.wrap_n and pane.wrap_line[pane.context_rows] == t.line) {
- for (pane.wrap_line[0..pane.context_rows]) |row| if (row == line_at) return;
+ for (pane.wrap_line[@min(covered, pane.context_rows)..pane.context_rows]) |row| if (row == line_at) return;
}
- const body: i64 = shownNow(pane);
+ const full: i64 = shownNow(pane);
+ const body: i64 = @max(1, full - hidden);
const margin: i64 = @min(margin_rows, @divTrunc(body - 1, 2));
// The row in the body (the map's, made just now), or none: the line is
// above the top, or below the map. Inside the band the view stays, and
// no line is walked (a key's step, nearly always).
- const mapped: i64 = pane.wrapRow(tab, line_at, col).row - @as(i64, pane.context_rows);
- const row: ?i64 = if (mapped >= 0 and mapped < @max(pane.wrap_n, pane.rows) -| pane.context_rows) mapped else null;
+ const mapped: i64 = pane.wrapRow(tab, line_at, col).row - @as(i64, pane.context_rows) - hidden;
+ const row: ?i64 = if (mapped >= -hidden and mapped < @as(i64, @max(pane.wrap_n, pane.rows) -| pane.context_rows) - hidden) mapped else null;
if (row) |r| if (r >= margin and r <= body - 1 - margin) return;
const line: usize = @intCast(@max(0, line_at));
// The line walked once and no further than the view needs (`Bound`: a
@@ -2097,7 +2118,7 @@ pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) voi
const whole = at.rows <= body - 2 * margin;
if (if (row) |r| r < margin else line <= t.line) {
if (pane.follow_edges & 1 != 0) return;
- setTop(pane, walkKnown(tab, pane, .{ .line = line, .row = if (whole) 0 else at.row }, -margin, known).to);
+ setTop(pane, walkKnown(tab, pane, .{ .line = line, .row = if (whole) 0 else at.row }, -margin - hidden, known).to);
} else if (if (row) |r| r > body - 1 - margin else true) {
if (pane.follow_edges & 2 != 0) return;
// The margin only reveals text: a pane its whole text fits in
@@ -2108,7 +2129,7 @@ pub fn show(tab: u16, pane: *Pane, line_at: i32, col: i32, margin_rows: i64) voi
const stop = @max(line, nlines(pane.gpa, f) -| 1 -| @intFromBool(std.mem.endsWith(u8, f.content, "\n")));
if (past.line > stop) past = .{ .line = stop, .row = lineRows(tab, pane, stop) - 1 };
}
- setTop(pane, walkKnown(tab, pane, past, -(body - 1), known).to);
+ setTop(pane, walkKnown(tab, pane, past, -(full - 1), known).to);
}
}
diff --git a/core/Pick.zig b/core/Pick.zig
index b76020ca..12062894 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -125,6 +125,9 @@ aside_top: usize = 0,
/// again on the frame after the cursor moves to another, never on the key
/// that moved it, and on the frame a row first comes under it.
shown: u32 = no_row,
+/// A place shown in its landing pane's body since it unrolled: the band
+/// takes its rows from that body (`previewing`).
+previewed: bool = false,
/// The preview on (M-p).
previews: bool = true,
/// Marked rows (Tab), by what each is (`idOf`), in order.
@@ -186,6 +189,18 @@ pub fn live(p: *const Pardes) ?*Pick {
return if (pk.unrolled) pk else null;
}
+/// Whether pane `id`'s body is the live picker's preview: a place shown in
+/// it. Its band then takes its rows from the body, which starts under the
+/// band (Pardes.sync), as a file's first lines could not be put under it
+/// otherwise (UX DESIGN I1's "a picker's landing line at a third below
+/// the band" for Find's line 1: W1's reading); before that, and at rest
+/// again, the pane's own text stays where it was under the band.
+pub fn previewing(p: *const Pardes, id: usize) bool {
+ const pk = live(p) orelse return false;
+ const pane = p.panes[id] orelse return false;
+ return pk.previewed and pane.serial == pk.landing;
+}
+
/// A picker of `source` asked from pane `from`, unrolled in the tag of the
/// pane its Enter will land in (SPEC §3.5), its field `query`. `rows` are
/// a list's (`source` `list`, titled `word`).
@@ -277,6 +292,7 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void {
s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) };
pk.unrolled = true;
pk.shown = no_row;
+ pk.previewed = false;
// The whole window previews a theme.
if (pk.source == .themes) s.previewing = .full;
if (p.paneBySerial(pk.landing)) |id| {
@@ -852,6 +868,13 @@ fn preview(p: *Pardes, pk: *Pick) void {
pane.places.clear(p.gpa);
}
pane.hscroll = 0;
+ pk.previewed = true;
+ p.sync();
+ }
+ // The body under the band from the first place it shows (previewing):
+ // laid out again before the place is put in its rows.
+ if (!pk.previewed) {
+ pk.previewed = true;
p.sync();
}
const keyboard = p.view().active;
@@ -1802,7 +1825,7 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
_ = try p.render(a);
const r = p.view().rects[reader];
try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme());
- try std.testing.expect(p.panes[reader].?.band_rows >= 1);
+ try std.testing.expect(Band.covered(p, p.panes[reader].?, reader).band >= 1);
// Esc: the reader made for it goes, the asker as it was.
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqual(npanes, paneCount(p));
@@ -1859,14 +1882,14 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin
settle(p);
const reader = p.paneBySerial(live(p).?.landing).?;
p.sync();
- const rows = p.panes[reader].?.band_rows;
+ const rows = Band.covered(p, p.panes[reader].?, reader).band;
// One or two files listed: four rows, ground under them.
try std.testing.expectEqual(@as(u16, 4), rows);
for ("zzq") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
settle(p);
p.sync();
try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?));
- try std.testing.expectEqual(rows, p.panes[reader].?.band_rows);
+ try std.testing.expectEqual(rows, Band.covered(p, p.panes[reader].?, reader).band);
}
test "a picker's band is capped once at open at 40 % of its host pane's rows; the host borrows from its column for a body of 60 % before the band gives way: a Grep from a held pane at 100x30 previews 8 rows at least" {
@@ -1896,9 +1919,13 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th
p.sync();
const pane = p.panes[reader].?;
const r = p.view().rects[reader];
- try std.testing.expectEqual(@min(Band.Cursor.shown, at_open * 2 / 5), pane.band_rows);
- try std.testing.expect(r.h - pane.tag_rows >= 8);
- try std.testing.expect(@as(u32, r.h - pane.tag_rows) * 5 >= @as(u32, r.h) * 3);
+ const at = Band.covered(p, pane, reader);
+ try std.testing.expectEqual(@min(Band.Cursor.shown, at_open * 2 / 5), at.band);
+ // The rows under the band, the preview's (no row previewed yet: the
+ // band over the reader's text, UX DESIGN I1).
+ const under = r.h - @max(pane.tag_rows, at.text + at.band);
+ try std.testing.expect(under >= 8);
+ try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3);
}
test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" {
@@ -2620,3 +2647,56 @@ test "Backspace on a Messages picker's empty field goes back to the level it was
p.sync();
_ = try p.render(frame.allocator());
}
+
+test "a picker's preview starts under its band: its landing line ⌈visible/3⌉ rows below the band's last row, a file's line 1 on the row right under it; before its first row and after Esc the pane's own text where it was at rest (UX DESIGN I1, W1's reading)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(std.testing.allocator);
+ for (1..121) |i| try text.print(std.testing.allocator, "line {d} of the file\n", .{i});
+ const path = try testFile(p, &tmp, "long.zig", text.items);
+ defer p.gpa.free(path);
+ var own: std.ArrayList(u8) = .empty;
+ defer own.deinit(std.testing.allocator);
+ for (1..81) |i| try own.print(std.testing.allocator, "own {d}\n", .{i});
+ const pane = try p.setTestFile(own.items);
+ const id = p.view().active;
+ pane.focus = .body;
+ for ("75j") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ p.sync();
+ const r = p.view().rects[id];
+ const rest = .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) };
+ try std.testing.expect(rest[2] > 0);
+ const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:60:1 line 60 of the file\n{s}:1:1 line 1 of the file\n", .{ path, path });
+ defer std.testing.allocator.free(rows);
+ open(p, id, .list, "Refs", "", rows);
+ p.sync();
+ // In the pane itself (it reads), no row shown yet: its text stays.
+ try std.testing.expectEqual(id, p.paneBySerial(live(p).?.landing).?);
+ try std.testing.expect(!previewing(p, id));
+ try std.testing.expectEqual(rest, .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) });
+ try std.testing.expect(Band.covered(p, pane, id).over > 0);
+ // The first row shown: the body under the band, line 60 a third of
+ // its rows down.
+ p.update(.tick);
+ try std.testing.expect(previewing(p, id));
+ try std.testing.expectEqualStrings(path, pane.file.?.path);
+ const at = Band.covered(p, pane, id);
+ try std.testing.expectEqual(@as(u16, 0), at.over);
+ try std.testing.expectEqual(p.tagTop(pane, r) + at.text + at.band, p.bodyTop(pane, r));
+ try std.testing.expectEqual(@as(usize, 59 - (pane.rows + 2) / 3), pane.file.?.scroll);
+ // Line 1: on the row right under the band.
+ p.update(.{ .key = .{ .cp = Key.down } });
+ p.update(.tick);
+ try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll);
+ try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
+ // Esc: the pane's own text, where it was at rest.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ p.sync();
+ try std.testing.expect(live(p) == null);
+ try std.testing.expectEqual(rest, .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) });
+ try std.testing.expect(std.mem.startsWith(u8, pane.file.?.content, "own 1\n"));
+}
diff --git a/core/Prompt.zig b/core/Prompt.zig
index 706ff54d..c54bb228 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -1803,3 +1803,45 @@ test "C-r's history has the band's cursor like any list (UX D5): `▶` on its ne
try std.testing.expectEqualStrings("self", p.registers.value('/', 0).?);
try std.testing.expectEqualStrings("self", p.prompt_history.search.get(1).?);
}
+
+test "a search's current hit under C-r's band is put in the rows the band leaves the body, the band over its top rows; one already there is not moved (UX DESIGN I1, D14)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(std.testing.allocator);
+ for (1..201) |i| try text.print(std.testing.allocator, "{s} {d}\n", .{ if (i == 105 or i == 125) "the hit on row" else "a row", i });
+ const pane = try p.setTestFile(text.items);
+ // A history whose lines all hold `hit`: C-r's band as tall as they.
+ for ([_][]const u8{ "/hitA", "/hitB", "/hitC", "/hitD", "/hitE", "/hitF", "/hitG", "/hitH" }) |q| {
+ typeKeys(p, q);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ }
+ try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row);
+ // The view at line 100, the caret on its first row; line 105 the
+ // fifth row of the body, where the band will be.
+ panes.File.setTop(pane, .{ .line = 99 });
+ pane.body.cur_row = 99;
+ p.sync();
+ typeKeys(p, "/");
+ p.update(.{ .key = .{ .cp = 'r', .ctrl = true } });
+ p.sync();
+ const id = p.view().active;
+ const rows = pane.rows;
+ const at = Band.covered(p, pane, id);
+ try std.testing.expect(at.band >= 8 and pane.view.covered > 6);
+ try std.testing.expectEqual(@as(usize, 99), pane.file.?.scroll);
+ typeKeys(p, "hit");
+ p.sync();
+ // The hit, line 105, under the band: in the body's visible rows.
+ try std.testing.expectEqual(@as(i32, 104), pane.body.cur_row);
+ const row = @as(usize, @intCast(pane.body.cur_row)) - pane.file.?.scroll;
+ try std.testing.expect(row >= pane.view.covered and row < rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ // The next keys keep the hit where it is: it is visible.
+ const top = pane.file.?.scroll;
+ typeKeys(p, " on");
+ p.sync();
+ try std.testing.expectEqual(@as(i32, 104), pane.body.cur_row);
+ try std.testing.expectEqual(top, pane.file.?.scroll);
+}
diff --git a/core/TagState.zig b/core/TagState.zig
index 1e8b4dea..3bf67e5e 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -760,11 +760,11 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
// The rolled level breaks between its children only (UX D2), each row
// after the first from the first child's column, its spines on through
// it; three rows at most, the last ending `+N ↓` (N the children not
- // shown, `↓` unrolls them) when they do not fit. A terminal's to the
- // rows its own text takes: its pty is its body, and a which-key that
- // took a row would resize the program under it at every SPC.
+ // shown, `↓` unrolls them) when they do not fit. Rows past the tag's
+ // own are drawn over the body (UX DESIGN I1), a terminal's too: its pty
+ // keeps its size.
const tab = p.settings.tab;
- const most: usize = if (pane.isTerminal()) @import("layout.zig").wantedTagRows(p, id) else 3;
+ const most: usize = 3;
var children: [bindings.max_children]bindings.Child = undefined;
var level = bindings.level(p, cur.root, cur.path, &children);
const used = s.used[node.group];
@@ -1087,14 +1087,14 @@ test "SPC ? is Help over every root's leaves: typed in its head, filtered by the
_ = try p.render(a);
const r = p.view().rects[p.view().active];
try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme());
- try std.testing.expect(pane.band_rows >= 4);
+ try std.testing.expect(pardes.Band.covered(p, pane, p.view().active).band >= 4);
try std.testing.expect(p.surface.cursor != null and p.surface.cursor.?.bar);
// Enter runs it, typed as its keys, and the tag is back at rest.
const wrapped = p.settings.wrap;
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(p.settings.wrap != wrapped);
try std.testing.expectEqual(Kind.rest, s.kind);
- try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+ try std.testing.expectEqual(@as(u16, 0), pardes.Band.covered(p, pane, p.view().active).band);
}
test "? down a level is Help for that level; Backspace on its empty field goes back to the level, Esc to rest" {
@@ -1141,7 +1141,7 @@ test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc
try std.testing.expect(s.found);
try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys g ▸ d Def"));
// The level unrolled under the tag, the leaf on the cursor, its doc.
- try std.testing.expect(pane.band_rows >= 4);
+ try std.testing.expect(pardes.Band.covered(p, pane, p.view().active).band >= 4);
_ = try p.render(a);
const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
var text: std.ArrayList(u8) = .empty;
@@ -1165,7 +1165,7 @@ test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(Kind.rest, s.kind);
try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
- try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+ try std.testing.expectEqual(@as(u16, 0), pardes.Band.covered(p, pane, p.view().active).band);
}
test "C-w's level is window mode's, shown at once and kept while its keys move the outline, until Enter" {
@@ -1215,7 +1215,7 @@ test "a root struck in a pump, after its advance, wakes the loop for the next fr
try std.testing.expect(p.nextWake() == null);
}
-test "a terminal's rolled level takes no more tag rows than its own text: its pty keeps its size" {
+test "a terminal's rolled level takes no more tag rows than its own text, its rows past them drawn over its body: its pty keeps its size" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml", .cols = 40, .rows = 30 });
defer p.deinit();
@@ -1258,7 +1258,7 @@ test "a rolled level fits its rows at every width: its `…`, its groups' `…`
};
}
-test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC's: its pty is never resized" {
+test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC's, its rows past them drawn over its body: its pty is never resized" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml", .cols = 100, .rows = 30 });
defer p.deinit();
@@ -1300,7 +1300,7 @@ test "a band over a terminal is drawn over its body's top rows: its pty keeps it
for (keys) |k| p.update(.{ .key = k });
p.sync();
try std.testing.expect(hostOf(p) == shell);
- try std.testing.expectEqual(@as(u16, 0), pane.band_rows);
+ try std.testing.expect(pane.view.covered > 0);
try std.testing.expectEqual(tag_rows, pane.tag_rows);
try std.testing.expectEqual(rows, pane.rows);
try std.testing.expectEqual(cols, pane.cols);
@@ -1308,7 +1308,7 @@ test "a band over a terminal is drawn over its body's top rows: its pty keeps it
_ = try p.render(frame.allocator());
const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
try std.testing.expect(layer.kind == .band and layer.rows > 0);
- try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[shell]), layer.viewport.y);
+ try std.testing.expectEqual(p.tagTop(pane, p.view().rects[shell]) + pardes.Band.covered(p, pane, shell).text, layer.viewport.y);
p.update(.{ .key = .{ .cp = Key.escape } });
p.sync();
try std.testing.expectEqual(rows, pane.rows);
@@ -1316,7 +1316,7 @@ test "a band over a terminal is drawn over its body's top rows: its pty keeps it
}
}
-test "a tag out of rest keeps its rows at rest at least: a level shorter than its own text moves no body up" {
+test "a tag out of rest keeps exactly its rows at rest: a level shorter than its own text moves no body up, a band no body down" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 30 });
defer p.deinit();
_ = try p.setTestFile("one\n");
@@ -1325,15 +1325,15 @@ test "a tag out of rest keeps its rows at rest at least: a level shorter than it
const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
try std.testing.expect(tag_rows > 1);
// Help's head, a row, its band from the row under it: the rows the tag
- // keeps from rest are the band's first (UX E3), and the body gives only
- // what the band takes past them.
+ // keeps from rest are the band's first (UX E3), the rest drawn over the
+ // body, which keeps its rows (UX DESIGN I1).
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = '?' } });
p.sync();
try std.testing.expect(hostOf(p) != null);
- try std.testing.expectEqual(@as(u16, 1), pane.tag_rows - pane.band_rows);
- try std.testing.expect(pane.tag_rows >= tag_rows);
- try std.testing.expectEqual(rows + tag_rows, pane.rows + pane.tag_rows);
+ try std.testing.expectEqual(@as(u16, 1), pardes.Band.covered(p, pane, p.view().active).text);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
// With the keyboard in the tag (whose top row follows its caret) too:
// C-w's level, a line, in a tag of more rows.
toRest(p);
@@ -1343,7 +1343,7 @@ test "a tag out of rest keeps its rows at rest at least: a level shorter than it
p.clock.now_ns = p.view().tag_state.due_ns;
p.sync();
try std.testing.expect(hostOf(p) != null);
- try std.testing.expect(pane.tag_rows >= tag_rows);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
try std.testing.expectEqual(@as(u16, 0), pane.tag_top);
}
diff --git a/core/Trail.zig b/core/Trail.zig
index 96d505ae..aec320f7 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -998,7 +998,7 @@ test "a step whose tag would take a row its column cannot give folds to its newe
try std.testing.expect(std.mem.indexOf(u8, tag, "…") == null and std.mem.indexOf(u8, tag, full) != null);
}
-test "a band on a walked reading pane keeps it a body of 60 %: the layout's floor counts its tag at rest whole, as the sync after it keeps it (a pane the layout has given its width and not yet its height is never cut)" {
+test "a band on a walked reading pane is whole: the layout's floor counts its tag at rest whole, as the sync after it keeps it (a pane the layout has given its width and not yet its height is never cut)" {
var f: Fixture = .{ .p = undefined, .tmp = undefined };
try f.init(60);
defer f.deinit();
@@ -1030,9 +1030,11 @@ test "a band on a walked reading pane keeps it a body of 60 %: the layout's floo
p.sync();
for ([_]u21{ ' ', '?', 'q', 'q', 'x', 'q' }) |key| p.update(.{ .key = .{ .cp = key, .text = &[_]u8{@intCast(key)} } });
p.sync();
- try std.testing.expect(pane.band_rows > 0);
- const at = v.rects[r];
- try std.testing.expect((at.h - pane.tag_rows) * 5 >= at.h * 3);
+ const at = pardes.Band.covered(p, pane, r);
+ try std.testing.expect(at.band > 0);
+ try std.testing.expectEqual(pardes.Band.takes(p, r), at.band);
+ try std.testing.expectEqual(layout.wantedTagRows(p, r), pane.tag_rows);
+ try std.testing.expect(v.rects[r].h >= @max(pane.tag_rows, at.text + at.band));
p.update(.{ .key = .{ .cp = pardes.Key.escape } });
p.sync();
try std.testing.expect(pardes.TagState.hostOf(p) == null);
diff --git a/core/bindings.zig b/core/bindings.zig
index ab00c1da..3884aca0 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -608,7 +608,7 @@ test "\" shows the registers rolled, the ones holding something, each its value
// beside them.
p.update(.{ .key = .{ .cp = Key.down } });
try std.testing.expect(p.view().tag_state.unrolled);
- try std.testing.expect(pane.band_rows >= 4);
+ try std.testing.expect(pardes.Band.covered(p, pane, p.view().active).band >= 4);
_ = try p.render(a);
const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
var band: std.ArrayList(u8) = .empty;
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 5e23a415..9e7f6f08 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -1322,13 +1322,15 @@ test "a motion root's level paints its targets in place of their lines' numbers,
p.update(.{ .key = .{ .cp = 'g', .text = "g" } });
try std.testing.expectEqual(@as(i32, 5), pane.body.cur_row);
for ("4k") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
- // `g`: its first and last lines.
+ // `g`: its first and last lines; its first under the level's rows
+ // drawn over the body's top (UX DESIGN I1: a target on a covered line
+ // is hidden until rest), its last painted.
p.update(.{ .key = .{ .cp = 'g' } });
p.advance(p.clock.now_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
_ = frame.reset(.retain_capacity);
s = try p.render(a);
- try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y, number, &buf), 'g') != null);
+ try std.testing.expect(pardes.Band.covered(p, pane, id).over > 0);
try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 6, number, &buf), 'e') != null);
p.update(.{ .key = .{ .cp = Key.escape } });
// `m` unrolled, its cursor on `i`: the inside of the braces around the
diff --git a/core/draw.zig b/core/draw.zig
index 8f690e8e..2553d5be 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -362,11 +362,26 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
s.body_layers[id].rows = 0;
try renderPane(p, s, arena, pane, v.rects[id], id, id == v.active);
}
- // A band over a terminal's or a kind's body (Band.over), drawn after
- // the body it covers.
- if (TagState.hostOf(p)) |id| if (p.panes[id]) |pane| if (pane.band_rows == 0) {
- const rows = pardes.Band.shownRows(p, pane, id);
- if (rows > 0) try joinBand(p, s, arena, pane, v.rects[id], id, id == v.active, rows);
+ // A tag out of rest after every body (UX DESIGN I1): its head and its
+ // band past its own rows are drawn over the top rows of its body,
+ // which stay where they were; beside them the grip's column on the
+ // tag's ground, and a caret under them hidden until rest.
+ if (TagState.hostOf(p)) |id| if (p.panes[id]) |pane| if (v.rects[id].w > config.GUTTER and v.rects[id].h > 0) {
+ const r = v.rects[id];
+ const at = pardes.Band.covered(p, pane, id);
+ const y = p.tagTop(pane, r) + pane.tag_rows;
+ const rows = @min(at.over, r.h -| pane.tag_rows);
+ if (rows > 0) {
+ s.fill(r.x, y, config.GUTTER, rows, .{ .bg = .{ .rgb = tagGround(p, pane, id == v.active) }, .font_role = .tagline });
+ if (s.cursor) |c| if (c.x >= r.x and c.x < r.x + r.w and c.y >= y and c.y < y + rows) {
+ s.cursor = null;
+ };
+ if (s.body_layers[id].cursor) |c| if (pane.file != null and c.y < panes.File.coveredRows(pane)) {
+ s.body_layers[id].cursor = null;
+ };
+ }
+ try joinPaneTag(p, s, arena, pane, r, id, id == v.active, at.text);
+ if (at.band > 0) try joinBand(p, s, arena, pane, r, id, id == v.active, at);
};
// Each notice once, as a tag layer, and the grid's chip a copy of it.
for (s.regionList()) |region| {
@@ -503,10 +518,8 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
.tty => config.tag_tty,
}, box_style);
- try joinPaneTag(p, s, arena, pane, r, id, active);
- // The keyboard is in the head's field: its caret, not the body's.
- const head_caret = if (typing) s.cursor else null;
- if (pane.band_rows > 0) try joinBand(p, s, arena, pane, r, id, active, pane.band_rows);
+ // Out of rest its tag is drawn after the bodies, over its own (render).
+ if (!pardes.Trail.outOfRest(p, pane)) try joinPaneTag(p, s, arena, pane, r, id, active, @min(pane.tag_rows, MAX_TAG_ROWS));
// Folded panes retain their body state, but neither body pixels nor
// its cursor belong outside the one-row tag rectangle.
@@ -541,9 +554,11 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
}
try body_layer.joinBody(p, s, arena, pane, r, id, active, rail.*);
+ // The keyboard is in the head's field: its caret (render), not the
+ // body's.
if (typing) {
s.body_layers[id].cursor = null;
- s.cursor = head_caret;
+ s.cursor = null;
}
if (pane.layers.heat > 0) @import("jj.zig").railHeat(p, s, pane, id, rail.rect);
// A terminal panned to its cursor in a view shorter than it: an arrow
@@ -830,19 +845,18 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
}
}
-/// A pane's tag rows, painted once into their layer, a row to a line, and
-/// copied into the grid; the grid's caret where the layer has it.
-fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
+/// A pane's tag's `rows` text rows (MAX_TAG_ROWS at most; out of rest its
+/// head's, Band.covered, past its own rows over its body), painted once
+/// into their layer, a row to a line, and copied into the grid; the grid's
+/// caret where the layer has it.
+fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void {
const v = p.view();
const capacity = layout.tagCapacity(p, r.w -| TAG_TEXT_INSET);
// Too narrow for a layer: only the grid's gap cell.
- if (r.w <= TAG_TEXT_INSET) return paintPaneTag(p, s, arena, pane, r, id, active);
+ if (r.w <= TAG_TEXT_INSET) return paintPaneTag(p, s, arena, pane, r, id, active, rows);
const chrome = p.chromeTheme();
const region = s.region(.tag, id).?;
const tag = (try tagline.shownTag(p, arena, pane)).text;
- // The tag's text rows; the band's under them are its own layer. A
- // tag's own are MAX_TAG_ROWS at most (Pardes.sync).
- const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS);
// As wide as the widest row it shows, and never narrower than its
// viewport.
var widest: usize = 0;
@@ -854,7 +868,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
const storage = try arena.alloc(Cell, pitch * rows);
@memset(storage, .{});
var temporary: Surface = .{ .cols = columns + TAG_TEXT_INSET, .rows = rows, .cells = storage, .tab = p.settings.tab };
- try paintPaneTag(p, &temporary, arena, pane, .{ .x = 0, .y = 0, .w = columns + TAG_TEXT_INSET, .h = rows }, id, active);
+ try paintPaneTag(p, &temporary, arena, pane, .{ .x = 0, .y = 0, .w = columns + TAG_TEXT_INSET, .h = rows }, id, active, rows);
// Window mode (layout.windowKey): the outlined pane's tag in the
// selection's colours.
if (v.window_pick == id) {
@@ -889,12 +903,14 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
}
}
-/// The band under pane `id`'s tag text (Band.zig), painted once into its
-/// layer at the tagline's pitch, a row to a line, and copied into the
-/// grid: the spines and steps in the tag's tint, the keys in the key ink,
-/// the cursor's row tinted as a selection.
-fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void {
+/// The band under pane `id`'s tag text (Band.zig), its `drawn.band` rows
+/// under the head's `drawn.text`, painted once into its layer at the
+/// tagline's pitch, a row to a line, and copied into the grid: the spines
+/// and steps in the tag's tint, the keys in the key ink, the cursor's row
+/// tinted as a selection.
+fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, drawn: pardes.Band.Covered) !void {
const layer = &s.tag_layers[pardes.BAND_LAYER];
+ const rows = drawn.band;
if (r.w <= TAG_TEXT_INSET) return;
const band = (try pardes.Band.of(p, arena, pane, id)) orelse return;
const chrome = p.chromeTheme();
@@ -973,9 +989,8 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
const count = @as(usize, columns) * rows;
if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count);
@memcpy(layer.cells, storage);
- // Under the tag's text rows; a terminal's or a kind's over its body's
- // top rows (Band.over).
- const y0 = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows);
+ // Under the head's rows, over the body's top ones (Band.covered).
+ const y0 = p.tagTop(pane, r) + drawn.text;
layer.kind = .band;
layer.id = @intCast(id);
layer.serial = pane.serial;
@@ -1023,13 +1038,12 @@ fn groundOf(p: *Pardes, pane: *const Pane, active: bool) colors.TagGround {
return if (active) .focused else .plain;
}
-fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
+fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void {
const th = p.theme();
const chrome = p.chromeTheme();
const tx = r.x + @min(TAG_TEXT_INSET, r.w);
const tw = r.w -| TAG_TEXT_INSET;
const tag_y = p.tagTop(pane, r);
- const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS);
const page_rgb = th.bg orelse th.tag_bg;
// Focus is visible along the tag without changing its live text grid.
const inks = chrome.roles.on(groundOf(p, pane, active));
@@ -1839,7 +1853,7 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d
p.sync();
const s = try p.render(a);
const r = p.view().rects[p.view().active];
- const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * (pane.tag_rows - pane.band_rows)];
+ const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * pardes.Band.covered(p, pane, p.view().active).text];
const Row = struct {
fn find(cells: []const Cell, word: []const u8) ?usize {
var at: usize = 0;
diff --git a/core/layout.zig b/core/layout.zig
index 4b5b7d2c..47f9bf0d 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -605,7 +605,7 @@ pub fn wantedTagRows(p: *Pardes, id: usize) u16 {
/// The rows pane `id`'s tag's text takes now: out of rest its head
/// (TagState) after what of its prefix stays (UX D1), wrapped at its width
/// as Pardes.sync wraps it; at rest what wantedTagRows says.
-fn headRows(p: *Pardes, id: usize) u16 {
+pub fn headRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return BOX_H;
if (pane.collapsed or !pane.tag_expanded) return BOX_H;
var wrap_room: [Pane.prefix_room]u8 = undefined;
@@ -1519,19 +1519,23 @@ pub fn compute(p: *Pardes) void {
/// The fewest rows a pane is laid out with: a terminal keeps its tag and
/// `min_body_rows` (a shorter one loses its prompt and reads busy for
/// ever), a text pane may shrink to its tag, as acme's windows do. A tag
-/// out of rest keeps its band and a body of 60 % of the pane and 6 rows at
-/// least (UX D6), borrowed from the column's other panes, which shrink to
-/// their tags until it rolls up (walk UI SPEC §3.6).
+/// out of rest has the rows for its head and its band, drawn over its body
+/// (UX DESIGN I1); a picker's (code actions' too: its body is the preview)
+/// a body of 60 % of the pane and 6 rows at least under them (UX D6). Those
+/// are borrowed from the column's other panes, which shrink to their tags
+/// until it rolls up (walk UI SPEC §3.6). A terminal's and a kind's size
+/// is their user's: a transient state never resizes the pty under a
+/// program or a kind's view (a PDF's), it is drawn over as much of them as
+/// it has (R3).
fn floorRows(p: *Pardes, id: usize) u16 {
const pane = p.panes[id] orelse return 0;
- const band = if (pardes.Band.over(pane)) 0 else pardes.Band.takes(p, id);
+ const band = if (pane.isTerminal() or pane.addon != null) 0 else pardes.Band.takes(p, id);
if (band > 0) {
- // Over its body as Pardes.sync lays it out (UX E3): the head's rows
- // and the band under them, or the rows the tag keeps from rest
- // where those are more; worked out from the state, never the last
- // sync's rows (the first layout after a head changed read the
- // rows of the one before, and the next moved the body).
+ // Worked out from the state, never the last sync's rows (the first
+ // layout after a head changed read the rows of the one before, and
+ // the next moved the body).
const above = @max(wantedTagRows(p, id), headRows(p, id) + band);
+ if (p.view().tag_state.kind != .pick) return above;
// A body of 60 % is one and a half times what is above it.
return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2);
}
diff --git a/core/mouse.zig b/core/mouse.zig
index 72f599dd..b62cec7e 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -911,21 +911,30 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
-const BandPoint = struct { id: usize, line: u16, col: u16 };
+/// A band's row, or a head's row past its tag's own (`head`), drawn over
+/// the body: a covered row belongs to the band, never to the body under it
+/// (UX DESIGN I1).
+const BandPoint = struct { id: usize, line: u16, col: u16, head: bool = false };
-/// The band row and column (at the tagline's pitch) a press is on: a
-/// window's layer hit, or a terminal's grid cell under a tag's text rows.
+/// The band row and column (at the tagline's pitch) a press is on, or the
+/// head's row over the body: a window's layer hit, or a grid cell under a
+/// tag's own rows.
fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
const v = p.view();
- if (v.pointer_tag_hit) |hit| return if (hit.kind == .band) .{ .id = hit.id, .line = hit.line, .col = hit.col } else null;
+ if (v.pointer_tag_hit) |hit| {
+ if (hit.kind == .band) return .{ .id = hit.id, .line = hit.line, .col = hit.col };
+ const pane = (if (hit.kind == .pane and hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
+ return if (hit.line >= pane.tag_rows) .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true } else null;
+ }
const id = paneAt(p, mcol, mrow) orelse return null;
const pane = p.panes[id].?;
- const rows = pardes.Band.shownRows(p, pane, id);
- if (rows == 0) return null;
+ const at = pardes.Band.covered(p, pane, id);
const r = v.rects[id];
- const top = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows);
- if (mrow < top or mrow >= top + rows or mcol < r.x + TAG_TEXT_INSET) return null;
- return .{ .id = id, .line = mrow - top, .col = mcol - (r.x + TAG_TEXT_INSET) };
+ const top = p.tagTop(pane, r);
+ if (mrow < top + @min(pane.tag_rows, at.text) or mrow >= top + at.text + at.band or mcol < r.x + TAG_TEXT_INSET) return null;
+ const col = mcol - (r.x + TAG_TEXT_INSET);
+ if (mrow < top + at.text) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
+ return .{ .id = id, .line = mrow - top - at.text, .col = col };
}
/// A press on a band (Band.zig), read-only text: the select button puts
@@ -934,6 +943,20 @@ fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void {
const v = p.view();
const arena = p.scratch.allocator();
+ // A head's row over the body: its words as the tag's first row's.
+ if (point.head) {
+ if (button != config.exec_button and button != config.look_button) return;
+ const shown = (tagline.shownTag(p, arena, p.panes[point.id].?) catch return).text;
+ var lines = std.mem.splitScalar(u8, shown, '\n');
+ for (0..point.line) |_| _ = lines.next();
+ const text = lines.next() orelse return;
+ const b = tagline.wordBoundsAtCol(text, panes.File.rawAtDisplay(p.settings.tab, text, point.col)) orelse return;
+ if (b.lo == b.hi) return;
+ const word = text[b.lo..b.hi];
+ if (v.tag_state.kind == .pick and button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", word);
+ pardes.TagState.toRest(p);
+ return exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", word);
+ }
if (button == config.select_button) {
const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
const ln = band.line(arena, p.settings.tab, point.line) catch return;
diff --git a/core/panes.zig b/core/panes.zig
index 4b9aa7a7..16b1d388 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -141,7 +141,17 @@ pub const Pane = struct {
pub const Cwd = union(enum) { none, inherited: *Pane, owned: []u8 };
pub const Focus = enum { body, tag };
- pub const SessionView = struct { wrap: bool = true, layered: bool = true, body_h: u32 = 0, tagline_h: u32 = 0, rect_h: u16 = 0 };
+ pub const SessionView = struct {
+ wrap: bool = true,
+ layered: bool = true,
+ body_h: u32 = 0,
+ tagline_h: u32 = 0,
+ rect_h: u16 = 0,
+ /// The grid rows its tag out of rest draws over the top of its
+ /// body (Band.covered): what a state shows there is placed under
+ /// them (File.show).
+ covered: u16 = 0,
+ };
terminal: ?*Term.State = null,
/// Its terminal's, kept by the pane, which a rollback puts back, not by
/// the emulator, which none does (a speculation writes them): the grid
@@ -298,12 +308,9 @@ pub const Pane = struct {
/// Rows the tag takes on screen: one per line of it, as many as the pane
/// has room for with a body row to spare. Set with the geometry in sync.
/// Pointer rows count from the tag's first, so a body starts at this one.
- /// Its last `band_rows` are the band unrolled under its text (Band.zig).
+ /// Out of rest its rows at rest: a head and a band past them are drawn
+ /// over the body (Band.covered), but under a picker's preview.
tag_rows: u16 = 1,
- /// Dumped as `tag_rows` is: what the next layout reads (floorRows takes
- /// the tag's own rows as their difference) is the last sync's, which a
- /// load cannot work out again where that sync held the band short.
- band_rows: u16 = 0,
/// The tag's first line on screen. A tag with more lines than rows
/// scrolls to keep its caret in view while it has the keyboard; pointer
/// rows count from this line, not the tag's first.
diff --git a/core/views.zig b/core/views.zig
index a81e8430..3b238258 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -41,7 +41,7 @@ pub const away_kept_ns: u64 = 30 * std.time.ns_per_s;
/// layout, which of its texts has the keyboard, how far it is scrolled (a
/// terminal's history too), and what the view's step measured of it (its
/// tag's rows, its bands).
-const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "docked_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "band_rows", "view", "layers", "notices", "pan", "follow_scroll", "scrolled_to" };
+const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "docked_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "layers", "notices", "pan", "follow_scroll", "scrolled_to" };
/// The body's: its cursor, selections and mode. Its undo stays the pane's.
const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" };
@@ -56,7 +56,6 @@ pub const PaneView = struct {
tag_scroll: u16 = 0,
tag_top: u16 = 0,
tag_rows: u16 = 1,
- band_rows: u16 = 0,
view: Pane.SessionView = .{},
layers: File.Layers = .{},
notices: Pane.Notices = .{},
@@ -581,18 +580,20 @@ pub fn within(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pa
const testing = std.testing;
const Key = pardes.Key;
-test "a view not live with its band open, dumped and loaded, draws before its next step: its band's rows as dumped, its tag's rows never past MAX_TAG_ROWS" {
+test "a view not live with its band open, dumped and loaded, draws before its next step: its band over its body as dumped, its tag's rows its rows at rest" {
const gpa = std.testing.allocator;
const dump = @import("dump.zig");
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 30 });
defer p.deinit();
const pane = try p.setTestFile("one\n");
- // SPC's level unrolled in view 0: its band's rows in the tag's.
+ p.sync();
+ const rest = pane.tag_rows;
+ // SPC's level unrolled in view 0: its band over the body's top rows.
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = Key.down } });
p.sync();
- const band = pane.band_rows;
- try testing.expect(band > 0 and pane.tag_rows - band <= pardes.MAX_TAG_ROWS and pane.tag_rows > pardes.MAX_TAG_ROWS);
+ const covered = pane.view.covered;
+ try testing.expect(covered > 0 and pane.tag_rows == rest);
// Another view live, view 0 parked, as a client's is when a join's
// (a replica's rollback's) dump is made.
const k = p.openView().?;
@@ -603,15 +604,15 @@ test "a view not live with its band open, dumped and loaded, draws before its ne
defer q.deinit();
try testing.expectEqual(pardes.walk.digest(Pardes, p), pardes.walk.digest(Pardes, q));
// View 0 drawn with no step first (a client's draw, a pump's other
- // views): its band as it was, the tag's own rows under the bound.
- try testing.expectEqual(band, q.panes[0].?.pv[0].band_rows);
+ // views): its band over its body as it was.
+ try testing.expectEqual(covered, q.panes[0].?.pv[0].view.covered);
_ = try drawOne(q, 0, .{ .ctx = null, .f = null });
- // The bound itself: a share whose band's rows are not counted.
- q.panes[0].?.pv[0].band_rows = 0;
+ // A share whose covered rows are not counted draws the same band.
+ q.panes[0].?.pv[0].view.covered = 0;
_ = try drawOne(q, 0, .{ .ctx = null, .f = null });
}
-test "a band its sync held short under a head of two rows, dumped and loaded: its rows are the never-loaded session's, and so is the next layout" {
+test "a picker's band in a short column, dumped and loaded: its rows are the never-loaded session's, and so is the next layout" {
const gpa = std.testing.allocator;
const dump = @import("dump.zig");
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 });
@@ -635,15 +636,17 @@ test "a band its sync held short under a head of two rows, dumped and loaded: it
p.stream.engine = .walk;
pardes.Pick.open(p, host, .find, "", "", "");
p.sync();
- try testing.expect(pane.band_rows > 0 and pane.band_rows < pardes.Band.takes(p, host));
- try testing.expect(pane.tag_rows - pane.band_rows >= 2);
+ const at = pardes.Band.covered(p, pane, host);
+ try testing.expect(at.band > 0 and at.band < pardes.Band.takes(p, host));
+ try testing.expect(at.text >= 2);
const bytes = try dump.byteDump(p);
defer gpa.free(bytes);
const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, bytes, null);
defer q.deinit();
- try testing.expectEqual(pane.band_rows, q.panes[host].?.band_rows);
+ try testing.expectEqual(pane.view.covered, q.panes[host].?.view.covered);
+ try testing.expectEqual(pane.tag_rows, q.panes[host].?.tag_rows);
// The next step lays the column out from the band's floor (layout
- // floorRows: the tag's own rows are its rows less the band's).
+ // floorRows, from the state alone).
p.update(.{ .resize = .{ .cols = 40, .rows = 40 } });
q.update(.{ .resize = .{ .cols = 40, .rows = 40 } });
try testing.expectEqual(p.view().rects[host], q.view().rects[host]);