summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 11:32:14 -0300
committerGabriel Schneider <[email protected]>2026-11-26 11:32:37 -0300
commit26e5fae651e4261321c2937094fdec7b7d3b299f (patch)
tree41fcfef30d83ce7dee3d6f6f582c054968f89ca3 /core/Pick.zig
parent5bfea157e191f2ce8442ddfa9af0955c345d1623 (diff)
downloadpardes-26e5fae651e4261321c2937094fdec7b7d3b299f.tar.gz
pardes-26e5fae651e4261321c2937094fdec7b7d3b299f.zip
Pick, Band, layout, Query, Trail: a picker hangs under the tag of the pane you are in, which keeps the keyboard, and only its preview goes to the pane its Enter lands in (UX DESIGN O1, binding; the user, about install74: "Why does the picker show in the middle on a pane? like I press spc b b and in the middle of the pane the picker is shown, shouldn't it be on the tagline?"); THE WAY IT WAS: Pick.unroll hosted the head and the band in the landing pane's tag (`s.host = pk.landing`), so from a held pane with no reader and no free space Pick.hostIn made an empty pane in the middle of it (landingFor, placeNew(.reader)) and hung the picker there while the keyboard stayed in the held pane, squeezed to 3 rows; Panes, which has no place to preview, still made that pane, left it empty and listed it (`@p3 +Preview`); THE CHANGE: Pick.unroll hosts under the asker (`s.host = pk.owner`); hostIn finds where the preview goes in O1's order (the asker when it reads or is untouched, else its reader, else free space, else a pane made under it as the reader would be) and makes no pane and sets nothing aside for Panes, Themes and code actions (landing = the asker; the notice row's `⏎ lands …` sentence not for Panes); `cap` is 40 % of the asker's rows at open; a pane made for the preview is an ordinary pane whose tag is `‹@pN ›` (W5's tagline, unchanged), with no head; Pick.previewPane names the pane the preview shows in, and the layout keeps it a body of 60 %, 6 rows at least, under its tag (layout.floorRows: its tag and, when it is the asker too, its head and band above that body, as before), while an asker that previews elsewhere covers its top rows as a level does (Band.covered keeps no body under its band; I1); the Panes list skips a picker's preview (Query.gather, `o.from == .preview`); M-h from Panes to a source that previews finds its preview pane as an opened one would (switchTo); a list word Looked at reopens under the reading pane whose trail holds it, which asks and previews it (reopen: owner = landing = that pane, the keyboard there); RUN (TEST FIRST): Pick "SPC b b from a held pane hangs under that pane's own tag (UX DESIGN O1): no pane made, nothing set aside, the keyboard in its field; a Panes list never names a picker's preview" (two panes, a held one and an untouched +New: the pane count as it was, landing the held pane, hostOf the held pane, its rest tag byte-equal, the head `␣ b Panes …` under it, no sentence, 2 rows; then a list from the held pane previews in the +New and M-h b lists the held pane alone: fails on the base at Pick.zig:3797, the landing the +New, serial 3 for 2) and Pick "a picker from a held pane with a reader hangs under the held pane's tag and previews in the reader, whose tag names its own file; Esc gives the reader its text back; switched from Panes, it previews where it would have" (fails on the base at Pick.zig:3860, hostOf the reader, 1 for 0), pass now; the tests that read the head on the landing pane read it on the asker (Pick's made-reader test, renamed: the head under the asker, the reader below it with no band, `^` in the asker's box; the 40 % test, renamed: the band from the asker's rows at open, the reader's body ≥ 8 rows and 60 % at 100x30; the act-row and band-height tests; the `‹@pN ›` test, renamed: its tag row, its body's `1▸const alpha` under it, the head under the asker's tag, W5's click part dropped for the next change; Trail's G 2e test: the host the held pane, the landing its reader); a user hit it with every picker started from a held pane; GATES (Debug tui): core-test 1168/1342 (174 skipped; the base's 1166/1340 + 2; one program's 7 cached on a rerun), shell-test 1383/1386 (3 skipped); the dump does not change (no pane, view or picker field); no frame or perf gate (the user's rule of 2026-11-26); load 1.7 to 10.3
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig264
1 files changed, 197 insertions, 67 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index e3972419..10f78208 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -1,11 +1,12 @@
//! A picker (pick-ui SPEC.md §5, direction E): a list of places, panes or
-//! names unrolled in the tag of the pane its Enter lands in (§3.5): the
-//! asking pane when it reads, else its reader, made for the picker when it
-//! has none and taken away again by Esc. Its query is typed in that tag's
-//! field (TagState.field), its rows hang in the band under it (Band.zig)
-//! eleven at a time around the cursor, and that pane's body is the preview:
-//! the current row's file at its line, its own text set aside meanwhile and
-//! put back when the picker rolls up.
+//! names hung under the tag of the pane that asked, which keeps the
+//! keyboard (UX DESIGN O1). Its query is typed in the head's field
+//! (TagState.field), its rows hang in the band under it (Band.zig) eleven
+//! at a time around the cursor, and the body of the pane its Enter lands in
+//! is the preview: the current row's file at its line, its own text set
+//! aside meanwhile and put back when the picker rolls up. That pane is the
+//! asking one when it reads or is untouched, else its reader, else free
+//! space, else one made under it for the picker and taken away by Esc.
//!
//! The rows are Query.zig's producers', re-presented: names scored by
//! Names.zig a frame's count at a time (Find's listing from the disk
@@ -93,12 +94,13 @@ word: Kind.Buf(24) = .{},
keys: Kind.Buf(4) = .{},
/// Where Find and Grep look; what the rows' paths are relative to.
dir: Kind.Buf(4096) = .{},
-/// The pane that asked, and the one its Enter lands in, by serial.
+/// The pane that asked, under whose tag it hangs, and the one its Enter
+/// lands in, whose body previews, by serial.
owner: u32 = 0,
landing: u32 = 0,
/// The landing pane was made for it: Esc takes it away.
made: bool = false,
-/// Its band's rows at most: 40 % of its host pane's rows at open (UX D6),
+/// Its band's rows at most: 40 % of its asking pane's rows at open (UX D6),
/// fixed: the layout that borrows the host's body from its column reads
/// it, and a pane laid out again changes it no more than typing does.
cap: u16 = 0,
@@ -219,6 +221,16 @@ pub fn previewing(p: *const Pardes, id: usize) bool {
return (pk.previewed or pk.source == .actions) and pane.serial == pk.landing;
}
+/// Whether pane `id` shows the live picker's preview, being its landing
+/// pane, for the layout: a body of 60 % kept under what is above it (UX
+/// D6, DESIGN O1), the head and the band among that when it asked too.
+/// Panes and Themes preview in no pane.
+pub fn previewPane(p: *const Pardes, id: usize) bool {
+ const pk = live(p) orelse return false;
+ const pane = p.panes[id] orelse return false;
+ return pane.serial == pk.landing and pk.source != .panes and pk.source != .themes;
+}
+
/// The live picker whose rows pane `pane`'s body previews, it being its
/// landing pane: what its tag names in place of the preview
/// (tagline.named, UX DESIGN M3); none for a themes or actions picker,
@@ -229,9 +241,9 @@ pub fn landingOf(p: *const Pardes, pane: *const Pane) ?*const Pick {
return pk;
}
-/// 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`).
+/// A picker of `source` asked from pane `from`, hung under its tag (UX
+/// DESIGN O1), its field `query`. `rows` are a list's (`source` `list`,
+/// titled `word`).
pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []const u8, rows: []const u8) void {
const asker = p.panes[from] orelse return;
TagState.toRest(p);
@@ -242,8 +254,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []
// Find and Grep from the work tree's root (W8), as other finders search.
pk.dir.set(if (source == .find or source == .grep) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker));
pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err);
+ pk.cap = p.view().rects[from].h * 2 / 5;
hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err);
- if (p.paneBySerial(pk.landing)) |host| pk.cap = p.view().rects[host].h * 2 / 5;
unroll(p, pk, query);
start(p, pk);
filter(p, pk);
@@ -354,30 +366,28 @@ fn nkept(p: *const Pardes) usize {
return n;
}
-/// Picker `pk` asked from pane `from`: the pane it lands in is `from` when
-/// it reads; its reader when it is held and has one; else an untouched
-/// pane, `from` itself first (UX J1), which previews as a reading pane does
-/// and is given back as it was on Esc; else a pane made where its reader
-/// would go, empty until the preview fills it. The keyboard stays where it
-/// was: the landing pane is the tag's host.
+/// Picker `pk` asked from pane `from`, which keeps the keyboard and hangs
+/// its head and band under its tag (UX DESIGN O1). The pane it lands in,
+/// whose body previews: `from` when it reads; its reader when it is held
+/// and has one; else an untouched pane, `from` itself first (UX J1), which
+/// previews as a reading pane does and is given back as it was on Esc;
+/// else a pane made where its reader would go, empty until the preview
+/// fills it. A source with nothing to preview makes no pane and sets
+/// nothing aside: Panes (a row is a pane on the screen), Themes (the whole
+/// window wears the row) and code actions (their edit in the asking text).
fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void {
+ defer p.view().active = from;
const asker = p.panes[from].?;
pk.owner = asker.serial;
+ pk.landing = asker.serial;
pk.made = false;
- // A theme is no place: its list is the asking pane's own tag (§3.5),
- // and its preview the whole window; an action's is that text's edit.
- if (pk.source == .themes or pk.source == .actions) {
- pk.landing = asker.serial;
- p.view().active = from;
- return;
- }
+ if (pk.source == .panes or pk.source == .themes or pk.source == .actions) return;
var reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker);
if (reader == null) if (layout.freeSpace(p, from, .reader)) |free| if (free == .pane) {
reader = free.pane;
};
pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial;
pk.made = reader == null;
- p.view().active = from;
}
/// A pane made for a picker where pane `from`'s reader goes: under it, or
@@ -393,14 +403,14 @@ fn landingFor(p: *Pardes, from: usize) !usize {
return free;
}
-/// Picker `pk` live in the live view's tag: its host its landing pane, its
-/// field `query`, the cursor where it was.
+/// Picker `pk` live in the live view's tag: hung under its asking pane's
+/// tag (UX DESIGN O1), its field `query`, the cursor where it was.
fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void {
const v = p.view();
const s = &v.tag_state;
s.kind = .pick;
s.pick = pk.id;
- s.host = pk.landing;
+ s.host = pk.owner;
s.field.set(query);
s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) };
pk.unrolled = true;
@@ -996,7 +1006,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi
/// previewing.
pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize {
const pk = live(p) orelse return null;
- if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists) return null;
+ if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists or pk.source == .panes) return null;
if (pk.landing == pk.owner) {
w.writeAll("⏎ lands here") catch return null;
} else {
@@ -1526,9 +1536,18 @@ fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void {
for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa);
pk.nrefined = 0;
pk.marks.clearRetainingCapacity();
+ const from_panes = pk.source == .panes;
pk.source = to;
pk.word.set(words.get(to).word);
pk.keys.set(words.get(to).keys);
+ // From Panes, which previews in no pane (hostIn), to a source that
+ // does: its preview where it would have been had it opened as this one.
+ if (from_panes and to != .panes) {
+ var query: Kind.Buf(256) = .{};
+ query.set(s.field.text());
+ hostIn(p, pk, p.paneBySerial(pk.owner) orelse p.view().active) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ unroll(p, pk, query.slice());
+ }
start(p, pk);
filter(p, pk);
}
@@ -1857,16 +1876,19 @@ pub fn walkList(p: *Pardes, id: usize, forward: bool) bool {
}
/// Look on a list word in pane `id`'s trail (SPEC §6.3), or a walk onto
-/// it at step `walking` (UX L'1): the list unrolled again in that pane's
-/// tag, its rows, marks, cursor and query as they were.
+/// it at step `walking` (UX L'1): the list unrolled again under that
+/// reading pane's tag, which asks it now and previews it, its rows, marks,
+/// cursor and query as they were.
pub fn reopen(p: *Pardes, id: usize, index: u32, walking: ?u8) void {
const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
const pane = p.panes[id] orelse return;
TagState.toRest(p);
p.resume_at = 0;
touch(p, pk);
+ pk.owner = pane.serial;
pk.landing = pane.serial;
pk.made = false;
+ p.view().active = id;
unroll(p, pk, pk.query.slice());
unrollRows(p, pk);
pk.walking = walking;
@@ -2189,7 +2211,7 @@ fn settle(p: *Pardes) void {
}
}
-test "a picker from a held pane unrolls in a reader made for it: its rows in the band, the body the current row's file, Esc takes the reader away" {
+test "a picker from a held pane hangs under that pane's tag, which keeps the keyboard; its preview in a reader made for it under it, whose tag is `‹@pN ›`: the body the current row's file, Esc takes the reader away (UX DESIGN O1)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -2211,12 +2233,13 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
const npanes = paneCount(p);
open(p, asker, .find, "", "", "");
const pk = live(p).?;
- // A reader made for it, under the asker; its tag is the picker's.
+ // A reader made for it, under the asker, which hangs the picker.
try std.testing.expectEqual(npanes + 1, paneCount(p));
try std.testing.expect(pk.made);
const reader = p.paneBySerial(pk.landing).?;
- try std.testing.expectEqual(@as(?usize, reader), TagState.hostOf(p));
+ try std.testing.expectEqual(@as(?usize, asker), TagState.hostOf(p));
try std.testing.expectEqual(asker, p.view().active);
+ try std.testing.expect(p.view().rects[reader].y > p.view().rects[asker].y);
settle(p);
try std.testing.expectEqual(@as(usize, 2), count(p, pk));
for ("pick") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
@@ -2225,19 +2248,20 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
- // Its tag the owner's word alone (UX DESIGN M3), the head under it.
+ // Its tag the owner's word alone (UX DESIGN M3, O1); the head under
+ // the asker's.
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, a, reader), "‹@p"));
- const tag = try headOf(p, a, reader);
- const first = tag[0..std.mem.indexOfScalar(u8, tag, '\n').?];
- try std.testing.expect(std.mem.startsWith(u8, first, "␣ f Find pick ") and std.mem.endsWith(u8, first, " 1/1"));
- try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null);
+ try std.testing.expectEqualStrings("", try headOf(p, a, reader));
+ const tag = try headOf(p, a, asker);
+ try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick ") and std.mem.indexOf(u8, tag, " 1/1") != null);
// The body previews the row's file, after a frame of its own.
p.update(.tick);
try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
_ = try p.render(a);
- const r = p.view().rects[reader];
+ const r = p.view().rects[asker];
try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme());
- try std.testing.expect(Band.covered(p, p.panes[reader].?, reader).band >= 1);
+ try std.testing.expect(Band.covered(p, p.panes[asker].?, asker).band >= 1);
+ try std.testing.expectEqual(@as(u16, 0), Band.covered(p, p.panes[reader].?, reader).over);
// 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));
@@ -2259,7 +2283,7 @@ test "a picker's act row is one row under the spines, two cells right of the las
Trail.keep(p.panes[asker].?);
p.stream.engine = .walk;
open(p, asker, .find, "", "", "");
- const reader = p.paneBySerial(live(p).?.landing).?;
+ const reader = asker;
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
@@ -2292,7 +2316,7 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin
p.stream.engine = .walk;
open(p, asker, .find, "", "", "");
settle(p);
- const reader = p.paneBySerial(live(p).?.landing).?;
+ const reader = asker;
p.sync();
const rows = Band.covered(p, p.panes[reader].?, reader).band;
// One or two files listed: four rows, ground under them.
@@ -2304,7 +2328,7 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin
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" {
+test "a picker's band is capped once at open at 40 % of its asking pane's rows; the pane it previews in borrows from its column for a body of 60 %: a Grep from a held pane at 100x30 previews 8 rows at least, in a reader made under it (UX D6, DESIGN O1)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -2322,20 +2346,21 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th
p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
p.stream.engine = .walk;
p.sync();
+ const at_open = p.view().rects[asker].h;
open(p, asker, .grep, "", "", "");
const reader = p.paneBySerial(live(p).?.landing).?;
- const at_open = p.view().rects[reader].h;
+ try std.testing.expect(reader != asker);
for ("pub fn") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
settle(p);
p.update(.{ .key = .{ .cp = Key.down } });
+ p.update(.tick);
p.sync();
- const pane = p.panes[reader].?;
- const r = p.view().rects[reader];
- const at = Band.covered(p, pane, reader);
+ const at = Band.covered(p, p.panes[asker].?, asker);
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 - (at.tag + at.over);
+ // The preview's rows under the reader's tag, no band over them.
+ const r = p.view().rects[reader];
+ try std.testing.expectEqual(@as(u16, 0), Band.covered(p, p.panes[reader].?, reader).over);
+ const under = r.h - p.panes[reader].?.tag_rows;
try std.testing.expect(under >= 8);
try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3);
}
@@ -3722,7 +3747,7 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l
p.update(.{ .key = .{ .cp = Key.escape } });
}
-test "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›`, the head under it; a click on it ends the picker as Esc does, the pane gone and the owner's text as it was (UX DESIGN M3)" {
+test "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›`, its body under it; the head hangs under the asking pane's tag (UX DESIGN M3, O1)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();
p.settings.jumps = .walk;
@@ -3752,20 +3777,125 @@ test "a pane made for a picker has no rest: its tag is its owner's word alone, `
const s = try p.render(a);
const r = p.view().rects[reader];
var row: std.ArrayList(u8) = .empty;
- for (0..2) |y| {
+ const ra = p.view().rects[asker];
+ for ([_]struct { y: u16, starts: []const u8 }{
+ // The tag's row, the owner's word; the body's under it.
+ .{ .y = r.y, .starts = std.mem.trimEnd(u8, owner, " ") },
+ .{ .y = r.y + 1, .starts = "1▸const alpha" },
+ // The head under the asker's tag.
+ .{ .y = ra.y + p.panes[asker].?.tag_rows, .starts = "␣ f Find " },
+ }) |want| {
row.clearRetainingCapacity();
- for (s.cells[(@as(usize, r.y) + y) * s.cols + r.x + pardes.TAG_TEXT_INSET ..][0 .. r.w - pardes.TAG_TEXT_INSET]) |cell| try row.appendSlice(a, cell.grapheme());
- // The tag's row, the owner's word; the head's under it.
- try std.testing.expect(std.mem.startsWith(u8, row.items, if (y == 0) std.mem.trimEnd(u8, owner, " ") else "␣ f Find "));
+ for (s.cells[@as(usize, want.y) * s.cols + r.x + pardes.TAG_TEXT_INSET ..][0 .. r.w - pardes.TAG_TEXT_INSET]) |cell| try row.appendSlice(a, cell.grapheme());
+ try std.testing.expect(std.mem.startsWith(u8, std.mem.trimStart(u8, row.items, " "), want.starts));
}
- // B3 on it: the picker ends, the pane made for it goes, and nothing
- // under the press is looked at.
- const held = p.panes[asker].?;
- const caret = .{ held.body.cur_row, held.body.cur_col };
- p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = r.x + pardes.TAG_TEXT_INSET + 1, .row = r.y } });
- p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = r.x + pardes.TAG_TEXT_INSET + 1, .row = r.y } });
- try std.testing.expect(live(p) == null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqual(npanes, paneCount(p));
- try std.testing.expectEqual(asker, p.view().active);
- try std.testing.expectEqual(caret, .{ held.body.cur_row, held.body.cur_col });
+}
+
+test "SPC b b from a held pane hangs under that pane's own tag (UX DESIGN O1): no pane made, nothing set aside, the keyboard in its field; a Panes list never names a picker's preview" {
+ 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();
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ exec.runBuiltin(p, .New, held, "New", null);
+ p.view().active = held;
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const rest = try a.dupe(u8, try tagOf(p, a, held));
+ const npanes = paneCount(p);
+ for (" bb") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ const pk = live(p).?;
+ try std.testing.expectEqual(Source.panes, pk.source);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expect(!pk.made);
+ try std.testing.expectEqual(p.panes[held].?.serial, pk.landing);
+ try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p));
+ try std.testing.expectEqual(held, p.view().active);
+ try std.testing.expectEqualStrings(rest, try tagOf(p, a, held));
+ try std.testing.expect(std.mem.startsWith(u8, try headOf(p, a, held), "␣ b Panes "));
+ settle(p);
+ p.update(.tick);
+ // Nothing previewed, nothing said of a preview: the held pane's own text.
+ try std.testing.expect(pk.aside == null and p.panes[held].?.file.?.output == null);
+ var said: [256]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&said);
+ try std.testing.expect(sentence(p, &w) == null);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ // A list from the held pane previews in the untouched +New (UX J1);
+ // switched to Panes, the +New previewing is not among its rows.
+ const rows = try std.fmt.allocPrint(a, "{s}:3:1 three\n", .{b_path});
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.tick);
+ const scratch = p.paneBySerial(live(p).?.landing).?;
+ try std.testing.expect(scratch != held);
+ try std.testing.expectEqualStrings(b_path, p.panes[scratch].?.file.?.path);
+ p.update(.{ .key = .{ .cp = 'h', .alt = true } });
+ p.update(.{ .key = .{ .cp = 'b', .text = "b" } });
+ try std.testing.expectEqual(Source.panes, live(p).?.source);
+ try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(Trail.untouched(p, p.panes[scratch].?));
+}
+
+test "a picker from a held pane with a reader hangs under the held pane's tag and previews in the reader, whose tag names its own file; Esc gives the reader its text back; switched from Panes, it previews where it would have (UX DESIGN O1)" {
+ 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();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ // Its reader: alpha.zig, a Look from it.
+ _ = look.open(p, held, a_path, .{ .line = 1, .col = 1 }, .replace);
+ p.sync();
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+ p.view().active = held;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const reader_tag = try a.dupe(u8, try tagOf(p, a, reader));
+ const npanes = paneCount(p);
+ const rows = try std.fmt.allocPrint(a, "{s}:3:1 three\n", .{b_path});
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.tick);
+ const pk = live(p).?;
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(p.panes[reader].?.serial, pk.landing);
+ try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p));
+ try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
+ try std.testing.expectEqualStrings(reader_tag, try tagOf(p, a, reader));
+ try std.testing.expectEqual(@as(i32, 2), p.panes[reader].?.body.cur_row);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+ try std.testing.expect(p.panes[reader].?.file.?.output == null);
+ // Panes first, from the held pane: nothing set aside; then M-h r,
+ // Recent, previews in the reader as a list opened there would.
+ open(p, held, .panes, "", "", "");
+ try std.testing.expectEqual(p.panes[held].?.serial, live(p).?.landing);
+ p.update(.{ .key = .{ .cp = 'h', .alt = true } });
+ p.update(.{ .key = .{ .cp = 'r', .text = "r" } });
+ try std.testing.expectEqual(Source.recent, live(p).?.source);
+ try std.testing.expectEqual(p.panes[reader].?.serial, live(p).?.landing);
+ try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
}