From 8d90edcec1ba432d0f67ecc3a79eb6bf193369ff Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 09:40:17 -0300 Subject: TagState, tagline, Band, draw, layout, mouse, Pick, Trail, Core: out of rest a pane's tag stays exactly as at rest and what the keyboard drives hangs under it, the head on the row under the tag's rows, then the band (UX DESIGN M, binding; the user, looking at a picker started in an empty pane whose tag had become `^ ␣ f Find ascii 1/1`: "doesn't it make sense to the search just show below the tagline instead of being search tagline then results?", then "Keep consistent, idk, yes"): for every state the keyboard drives (rolled and unrolled levels, `"`, Help, describe-key, every picker, every text prompt, `:`, rename, code actions) the tag keeps its mark, owner, trail, path, Keep, computed words and own text, its rows and its wrapping, the box alone saying `^` while typing; THE WAY IT WAS: the head (TagState.head) was the tag's text after a cut-down prefix (D1's owner and newest step, tagline.pathPrefix's out-of-rest branch, Trail's `.newest` part), so the path, Keep and the user's text left the screen while you typed, the key cells sat on the tag's row for a level and jumped with it, and a picker's preview in a reading pane would have named the previewed file had the path stayed; THE CHANGE: TagState.head is the head alone, laid out from the tag's text column on rows of its own (Builder's `lead` gone), and TagState.asking the question a tag says, which stays in the tag (UX D13, M1: questions unchanged); tagline.shownTail is the question or the own text in every state, pathPrefix the path in every state (the out-of-rest branch and Trail's `.newest` part, `newest_cells` and the `cut` buffers deleted); a pane a picker previews in names its own file, the one Pick.showText set aside (tagline.named, tagWords, and Trail.reading asking the same file, so its tint, Keep and words are the rest ones); a pane made for the picker (it has no rest) shows its owner's word alone, `‹@pN ›` (M3; P1's reading 2 reversed); Band.covered is the tag's rows at rest, then the head's rows, then the band's, `over` = head + band (no rows the head reused: M4), layout.headRows the head's own rows and floorRows the tag's rows plus the head's and the band's (a head that does not fit borrows from its column as a band does); draw.zig joinBand paints the head's rows as the band layer's first rows (its spans' inks moved there from paintPaneTag, its caret the band layer's cursor), the band's under them, the spines from the head's key cells on its own row; render draws the host's tag with its rest rows; mouse: a press on a tag out of rest ends its state as Esc does and then does what it does at rest (M3; a pane made for a picker goes with it and the press with it), bandPoint reads the head's rows as the band layer's first, and B1 in the head's field puts the field's caret there; edit.zig refuses an edit of a tag only while it asks; RUN (TEST FIRST): five new tests, each failing on the base (M2, 8959b031dc33) and passing now: TagState "out of rest a tag is drawn as at rest, the head hanging under it ..." (a `.list` picker in a reading pane that walked near.txt -> far.txt: the tag's rows cell for cell as at rest but the box, its path far.txt while the body previews near.txt, the head `␣ l Refs ... 1/1` on the next row, its count the row's last cells, the band under it; Esc, the rows as before: failed on the base at the tag text, `near.txt:2 › ␣ l Refs ...`), TagState "the key cells are one thing growing on the row under the tag ..." (`␣`, `␣ f`, `␣ f Find` in the same cells of the row under a two-row tag: failed on the base, `␣` on the tag's row), TagState "a click that gives the keyboard to another pane ends a level ...; one in the level's own tag ends it too, then does what it does there at rest ..." (was "... one in the level's own tag keeps it"; B1 on the tag's own word ends SPC's level and gives the tag the keyboard, B2 on `Wrap` ends Help and toggles wrap: failed on the base, the level kept), Pick "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›` ..." (B3 on it: the picker ends, the made pane goes, nothing under the press looked at: failed on the base, its tag `␣ f Find ...`), Command ": hangs its field under the tag, which stays as at rest; `:` on the empty field gives the keyboard to that tag's own text right above it ..." (failed on the base, the tag text `: ...`); the expectations that read the head through the tag's text read it from TagState.head now (TagState's testTag, Prompt's and Command's headOf, Pick's headOf; bindings, Messages, lsp/Ask, Trail, Band, draw, views: ~40), and the ones that read a body's first row while a prompt is up read the rows under the head's (Prompt's `/`, `s`, `|` tests, body_layer's current-place test, Ask's rename); views' short-column picker test runs at 15 rows (the head's row is one more covered row: at 12 the band had none left); the process test msg waits for the second reload by the notice row's `×2` (the pane's one line is under the `s` prompt's head now); AND A FAULT THIS MADE VISIBLE: code actions drew their edit's ghost lines from the body's top under a band drawn over it (Pick.previewing was a place's preview alone), so an edit on the first rows of a file was under the band; with the head's row one more covered row, test/behaviour/language_servers.zig's "SPC l a lists the server's code actions ..." failed (`let x = sum(1, 2);` at line 4 under the head and a 4-row band, not on the screen); THE FIX: code actions' body is their preview from the first (UX DESIGN I1: "a picker and code actions (whose body is the preview) keep D6"): Pick.previewing is true for them, so the body starts under the head and the band as a picker's preview does; the behaviour test passes now; GATES (Debug tui, this change): core-test 1166/1340 (174 skipped; M2's gate 1155/1329), shell-test 1381/1384 (3 skipped), behaviour-test 287/287 and --replay 287/287, pane-test 184/185 (1 skipped), term-test 17/17, kitty-test 45/45 (these three before the code-actions fix and two renames), process-test 8 of 149 failed (3 skipped): exactly the goldens with a frame out of rest (find, fsearch, leader, lsp, msg, pipe, selregex, ttyhelp), re-recorded and explained by the next change; the dump does not change (no pane or view field); no frame or perf gate (the user's rule of 2026-11-26); load 4.2 to 14.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Pick.zig | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 14 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Pick.zig b/core/Pick.zig index c05ed084..e3972419 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -209,11 +209,24 @@ pub fn live(p: *const Pardes) ?*Pick { /// 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. +/// again, the pane's own text stays where it was under the band. Code +/// actions' body is their preview from the first, their edit's ghost lines +/// in it (UX DESIGN I1: "a picker and code actions (whose body is the +/// preview) keep D6"): under the head and the band, never under them. 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; + return (pk.previewed or pk.source == .actions) and pane.serial == pk.landing; +} + +/// 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, +/// whose landing is the asking pane's own text. +pub fn landingOf(p: *const Pardes, pane: *const Pane) ?*const Pick { + const pk = live(p) orelse return null; + if (pk.landing != pane.serial or pk.source == .themes or pk.source == .actions) return null; + return pk; } /// A picker of `source` asked from pane `from`, unrolled in the tag of the @@ -790,9 +803,10 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me // ---- the tag ---- -/// The head of the landing pane's tag (SPEC §5.3): the key cells, the -/// source's word, the query, the count `cursor/total` and `•marked`; on a -/// second row the other sources' words, under spines from the key cells. +/// The head under the landing pane's tag (SPEC §5.3, UX DESIGN M2): the +/// key cells, the source's word, the query, the count `cursor/total` and +/// `•marked`; on a second row the acts and the other sources' words, under +/// spines from the key cells. pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const pk = live(p) orelse return null; const s = &p.view().tag_state; @@ -2155,6 +2169,12 @@ fn tagOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 { return pardes.tagline.tagText(p, arena, p.panes[id].?); } +/// The head under pane `id`'s tag (UX DESIGN M2); none at rest. +fn headOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 { + const h = try TagState.head(p, arena, p.panes[id].?); + return if (h) |made| made.text else ""; +} + fn paneCount(p: *const Pardes) usize { var n: usize = 0; for (p.panes) |slot| n += @intFromBool(slot != null); @@ -2205,9 +2225,9 @@ 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(); - const tag = try tagOf(p, a, reader); - // Out of rest no path (UX D1): not the previewed file's, not Keep; - // the head starts the tag's text. + // Its tag the owner's word alone (UX DESIGN M3), the head under it. + 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); @@ -2243,7 +2263,7 @@ test "a picker's act row is one row under the spines, two cells right of the las var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - const tag = try tagOf(p, a, reader); + const tag = try headOf(p, a, reader); var rows = std.mem.splitScalar(u8, tag, '\n'); try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find ")); const acts_row = rows.next().?; @@ -2315,7 +2335,7 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th 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); + const under = r.h - (at.tag + at.over); try std.testing.expect(under >= 8); try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3); } @@ -2345,7 +2365,7 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and try std.testing.expectEqual(@as(u16, 2), s.rows.at); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); - const refs = try tagOf(p, frame.allocator(), id); + const refs = try headOf(p, frame.allocator(), id); try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.indexOf(u8, refs, " 3/4 •1\n") != null); p.update(.{ .key = .{ .cp = 'a', .alt = true } }); try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len); @@ -2364,7 +2384,7 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and settle(p); try std.testing.expectEqual(@as(usize, 1), count(p, pk)); _ = frame.reset(.retain_capacity); - const refined = try tagOf(p, frame.allocator(), id); + const refined = try headOf(p, frame.allocator(), id); try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.indexOf(u8, refined, " 1/1\n") != null); // Backspace twice: the `w` goes, then the refinement, its query back. p.update(.{ .key = .{ .cp = Key.backspace } }); @@ -3179,8 +3199,8 @@ test "a picker's preview starts under its band: its landing line ⌈visible/3⌉ 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(u16, 0), pane.view.covered); + try std.testing.expectEqual(p.tagTop(pane, r) + at.tag + at.over, 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 } }); @@ -3701,3 +3721,51 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l try std.testing.expectEqualStrings("/", live(p).?.dir.slice()); 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)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + p.stream.engine = .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); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" }); + const npanes = paneCount(p); + open(p, asker, .find, "", "", ""); + const pk = live(p).?; + try std.testing.expect(pk.made); + const reader = p.paneBySerial(pk.landing).?; + settle(p); + p.update(.tick); + try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const owner = try std.fmt.allocPrint(a, "‹@p{d} › ", .{p.panes[asker].?.serial}); + try std.testing.expectEqualStrings(owner, try tagOf(p, a, reader)); + const s = try p.render(a); + const r = p.view().rects[reader]; + var row: std.ArrayList(u8) = .empty; + for (0..2) |y| { + 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 ")); + } + // 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); + 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 }); +} -- cgit v1.3 From 26e5fae651e4261321c2937094fdec7b7d3b299f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 11:32:14 -0300 Subject: 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 8 +- core/Pick.zig | 266 +++++++++++++++++++++++++++++++++++++++++--------------- core/Query.zig | 2 + core/Trail.zig | 6 +- core/layout.zig | 20 +++-- 5 files changed, 219 insertions(+), 83 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Band.zig b/core/Band.zig index 6e8f9589..5efe1a36 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -141,9 +141,9 @@ pub fn takes(p: *Pardes, id: usize) u16 { /// (UX DESIGN I1, M2): under its tag's rows (`tag`, its rows at rest, which /// no state changes), its head's (`head`), then the band's (`band`), as /// many as the pane has under its tag; `over` the two, 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 +/// rows of its body, which never move for them. A picker's band over the +/// pane its preview shows in keeps a body of `body_rows` under it (UX D6, +/// DESIGN O1), any other 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 { tag: u16, head: u16, band: u16, over: u16 }; pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered { @@ -153,7 +153,7 @@ pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered { // over it to them). const tag = @min(layout.wantedTagRows(p, id), pardes.MAX_TAG_ROWS, @max(pardes.BOX_H, h -| 1)); const head = @min(layout.headRows(p, id), h -| tag); - const keep: u16 = if (p.view().tag_state.kind == .pick) body_rows else 0; + const keep: u16 = if (@import("Pick.zig").previewPane(p, id)) body_rows else 0; const band = @min(takes(p, id), h -| tag -| head -| keep); return .{ .tag = tag, .head = head, .band = band, .over = head + band }; } 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 ")); - } - // 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); + 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)); + } + 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); } diff --git a/core/Query.zig b/core/Query.zig index f9651faf..96047ca1 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -749,6 +749,8 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: for (p.panes) |slot| { const other = slot orelse continue; if (other == self or other.query != null) continue; + // A picker's preview is no pane to go to (UX DESIGN O1). + if (other.file) |f| if (f.output) |o| if (o.from == .preview) continue; var buf: [4096 + 32]u8 = undefined; const what: []const u8 = if (other.file) |f| f.path else if (other.command) |c| c else other.cwdSlice(); const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}", .{ other.serial, relative(what, dir) }) catch continue; diff --git a/core/Trail.zig b/core/Trail.zig index e07e4357..f6cfec9a 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -948,10 +948,12 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC f.look(f.held, "rank.zig", 12); const r = p.view().active; // A list asked from the held pane (SPC e's places, a server's answer): - // its Enter lands in the reader, nothing made. + // hung under the held pane's tag (UX DESIGN O1), its Enter lands in the + // reader, nothing made. const rows = try std.fmt.bufPrint(&buf, "{s}/place.zig:8:1 of\n{s}/place.zig:40:1 Span\n", .{ f.dir, f.dir }); pardes.Pick.open(p, f.held, .list, "Refs", "", rows); - try std.testing.expectEqual(p.panes[r].?.serial, p.view().tag_state.host); + try std.testing.expectEqual(owner, p.view().tag_state.host); + try std.testing.expectEqual(p.panes[r].?.serial, pardes.Pick.live(p).?.landing); pardes.Pick.landHere(p); p.sync(); // The reader stepped (to another file: a pane of its own, its owner's diff --git a/core/layout.zig b/core/layout.zig index ae15c6e9..b15c7200 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -1608,22 +1608,24 @@ pub fn compute(p: *Pardes) void { /// `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 has the rows for its head and its band under it, drawn over -/// its body (UX DESIGN I1, M4); 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). +/// its body (UX DESIGN I1, M4). The pane a picker's preview shows in (code +/// actions' asking pane too: its body is the preview) has a body of 60 % of +/// the pane and 6 rows at least under its tag, and its head and band when +/// it asked (UX D6, DESIGN O1). 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 under = if (pane.isTerminal() or pane.addon != null) 0 else headRows(p, id) + pardes.Band.takes(p, id); - if (under > 0) { + const preview = pardes.Pick.previewPane(p, id); + if (under > 0 or preview) { // 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 = wantedTagRows(p, id) + under; - if (p.view().tag_state.kind != .pick) return above; + if (!preview) 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); } -- cgit v1.3 From e9991ca68067ee835af43868a193e8e6bd5dd420 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 11:37:09 -0300 Subject: mouse, TagState, keys, draw, Pick, exec, panes, Trail: the mouse never ends a picker or a prompt as a side effect: a click elsewhere leaves a state with a field waiting for the keyboard, the wheel scrolls the results, B1 on a row moves the cursor and B3 lands it, and only an act on the panes the picker lives in ends it first (UX DESIGN O2, O3, binding; the user: "Using the mouse just closes the picker? That is extremely bad the mouse shoudn't do implicit actions like this and I should be able to at least scroll on the resuls (doing a right click Look should also work though)"); THE WAY IT WAS: handleMouse's deferred check ended any state whose host was not `v.active` after any event (motion and the wheel too: from a held pane, whose picker the made pane hosted, a bare pointer motion ended it, UX7's t5), and W5's hostTagAt ended a state on any press on its tag; bandPress returned for the wheel, and its B3 landed through TagState.point and landHere whatever step the row was in (an act's row set the list's cursor; a theme's row rolled the picker up and wore nothing); THE CHANGE: TagState.waits, one bool (in the view, so in the dump and the digest), cleared by toRest: an event that moves the keyboard off the host, or B1 anywhere off the head and the band (the host's own tag, its body under the band, a header, a grip), leaves a state with a field (Help, a picker, a text prompt, `:`, rename) up and waiting, and ends a level, the registers or describe-key first, as Esc does (they hold no typed text; W5's hostTagAt branch deleted); while it waits, keys go where the keyboard is (keys.handleKey) and Esc ends it first, the pane's own Esc ladder from the next; B1 on its head or band, or a key that moves the keyboard to its pane (`C-w … ⏎`, `SPC w k`), gives it back; the waiting box shows its pane's mode and the field no caret (draw.zig: `typing` and the head's caret, behaviour only); TagState.pending echoes keys typed meanwhile on the notice row; bandPress: the wheel moves a picker's cursor by `wheel_rows` (Pick.wheel; the band's eleven and the preview follow as for a key) and Help's; B1 on a row is Pick.press (the list's cursor, or the act step's), B3 Enter there (a row landed, Shift-B3 below as S-Enter, an act applied, a source switched, a theme worn, an action applied); B2 and B3 on the head's words and B2 on a row's run with a picker or prompt up; B2 or B3 on the text a picker previews lands it first (Pick.previewsAt, landHere), then acts in the landed file; O3's guard, Pick.yieldFor: the live picker, waiting or not, ends as Esc does when Get, Undo, Redo, Save (acme's Put), Del or Keep is run on the pane it asks from or previews in (exec.runBuiltinFrom), when that pane is removed (panes.removePane) or a walk step replaces its file (Trail.show: a trail word, a Look landing there); anything else (Wrap, Snarf, a Look opening elsewhere) leaves it up; RUN (TEST FIRST): four mouse.zig tests, each failing on the change before (its `waits` checks taken out to compile there) and passing now: "the mouse never ends a picker as a side effect ..." (motion and the wheel over the preview and the window row, the wheel over the rows ±1 and the preview following, B1 on the third row and Up/Down in the field, B3 on the preview's text landing three.zig in the held pane's reader, Shift-B3 on a row opening a pane below: fails at mouse.zig:2121, the wheel moved no cursor, 0 for 1), "B1 in another pane: a picker waits ..." (B1 on the preview: waiting, the held box its mode, no caret in the head, `j` the reader's; B1 on the head back, `w` in the field; `C-w k ⏎` back; B1 under the band, `i`, Esc ends the picker with insert mode kept, the next Esc normal: fails at mouse.zig:2179, the picker ended), "B1 on the asking pane's own tag: the picker waits ...; B2 Del ends it first ... and closes the pane" (B2 Wrap leaves it up; B2 Del closes the held pane and the reader made for it: fails at mouse.zig:2238, the picker ended), "the act step and the rows under the mouse ..." (B2 Wrap in a row's text, B1 on `y Copy` sets the act step's cursor to 6, B2 on it copies `…one.zig:2`, the picker up: fails at mouse.zig:2286, act_at 0 for 6); TagState's W5 test, renamed, now asks Help to stay up after B2 Wrap in its tag and to wait after a click in the other pane, and an `s` prompt to wait the same; a user hit it with every click while a picker was up, and with any pointer motion from a held pane; GATES (Debug tui): core-test 1172/1346 (174 skipped: + 4; one program's 7 cached), shell-test 1387/1390 (3 skipped: + 4); the dump changes (TagState.waits): the dump fuzz and the soak run on the last change of this line; load 1.8 to 4.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Pick.zig | 58 ++++++++- core/TagState.zig | 36 +++++- core/Trail.zig | 3 + core/draw.zig | 7 +- core/exec.zig | 7 ++ core/keys.zig | 16 ++- core/mouse.zig | 349 +++++++++++++++++++++++++++++++++++++++++++++--------- core/panes.zig | 3 + 8 files changed, 408 insertions(+), 71 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Pick.zig b/core/Pick.zig index 10f78208..7bceab39 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -1942,13 +1942,69 @@ pub fn keyAtRest(p: *Pardes, k: Key) void { p.resume_at = 0; } -/// B3 on a picker's row (mouse.zig bandPress): Enter on it. +/// Enter on the live picker's current row: B3 on its text where it +/// previews (mouse.zig, UX DESIGN O3). pub fn landHere(p: *Pardes) void { const pk = live(p) orelse return; if (pk.source == .lists) return reopenListed(p, pk); if (pk.spine == .rows) land(p, .walk); } +/// A press on row `row` of the live picker's band (mouse.zig bandPress, UX +/// DESIGN O2): B1 (`enter` false) puts the cursor on it, the list's or the +/// act step's; B3 does what Enter does there (`below`: Shift-B3, as +/// S-Enter): the row landed, the act applied, the source switched to, the +/// theme worn, the action applied. A row of the act step or the source +/// spine is its key's, its first byte (actStep, steps). +pub fn press(p: *Pardes, row: Band.Row, enter: bool, below: bool) void { + const pk = live(p) orelse return; + const s = &p.view().tag_state; + if ((pk.spine == .acts or pk.spine == .sources) and row.key > 0) { + if (enter) return key(p, .{ .cp = row.text[0] }); + if (pk.spine == .acts) pk.act_at = @intCast(row.index); + return; + } + if (pk.spine != .rows or row.index >= count(p, pk)) return; + s.rows.at = row.index; + if (!enter) return; + if (pk.source == .lists) return reopenListed(p, pk); + if (pk.source == .themes or pk.source == .actions) return key(p, .{ .cp = Key.enter }); + land(p, if (below) .below else .walk); +} + +/// The wheel over the live picker's head or band (UX DESIGN O2): its +/// cursor `delta` rows on, the band's eleven following it and the preview +/// with them, as the keys move it. +pub fn wheel(p: *Pardes, delta: i32) void { + const pk = live(p) orelse return; + const s = &p.view().tag_state; + const n = @min(count(p, pk), std.math.maxInt(u16)); + if (n == 0 or pk.spine != .rows) return; + s.rows.at = @intCast(std.math.clamp(@as(i64, s.rows.at) + delta, 0, @as(i64, @intCast(n)) - 1)); + if (fuzzy(pk)) pk.names.reachTo(@as(usize, s.rows.at) + Band.Cursor.shown); +} + +/// Whether screen row `row` of pane `id` is text the live picker previews: +/// its landing pane's body, a place shown in it (UX DESIGN O3). B2 and B3 +/// there land it first: acting on the file is taking it. +pub fn previewsAt(p: *const Pardes, id: usize, row: u16) bool { + const pk = live(p) orelse return false; + const pane = p.panes[id] orelse return false; + if (pane.serial != pk.landing or !pk.previewed or pk.source == .themes or pk.source == .actions) return false; + return row >= p.bodyTop(pane, p.view().rects[id]); +} + +/// The live picker, waiting or not, ended as Esc ends it when what is about +/// to run changes or closes pane `id`, the pane it asks from or previews in +/// (UX DESIGN O3: Del, Get, Undo, Put, Keep, a walk step there, a Look that +/// lands there, the pane closed): the preview's own text back, a pane made +/// for it gone with it. Anything else leaves it up. +pub fn yieldFor(p: *Pardes, id: usize) void { + const pk = live(p) orelse return; + const pane = p.panes[id] orelse return; + if (pane.serial == pk.owner or pane.serial == pk.landing) TagState.toRest(p); +} + /// Enter in Lists (UX L'3): the kept picker under its cursor unrolled again /// as it was left, where Lists was asked from, and the newest now. fn reopenListed(p: *Pardes, pk: *Pick) void { diff --git a/core/TagState.zig b/core/TagState.zig index 11c3458b..622cb949 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -81,6 +81,14 @@ miss: u8 = 0, /// The leaf each group ran last, by its key (bindings.groups): the cursor /// starts there and the rolled level underlines it (SPEC §4.3). used: [bindings.ngroups]u8 = @splat(0), +/// A state with a field (Help, a picker, a text prompt, `:`, rename) whose +/// pane lost the keyboard to a click elsewhere (UX DESIGN O2): unrolled as +/// it was, its field drawn with no caret and its pane's box saying its +/// mode; keys go where the keyboard is, Esc ends it first, and a click on +/// its head or band, or a key that moves the keyboard back to its pane, +/// gives it the keyboard again. A level, the registers and describe-key, +/// which hold no typed text, end on such a click instead. +waits: bool = false, /// `.full` while the whole window previews a theme (a themes picker's /// row, `:theme `'s): its own again at rest. No pane dims out of rest /// (UX D9), so no pane's own bit is read. @@ -234,6 +242,7 @@ pub fn toRest(p: *Pardes) void { const s = &v.tag_state; if (s.kind == .prompt) Prompt.leave(p); s.kind = .rest; + s.waits = false; // The whole window previewed `:theme `'s row (Command.preview): its // own theme again (a themes picker's went as it rolled up). if (s.previewing.eql(.full)) @import("colors.zig").previewTheme(p, null); @@ -386,9 +395,10 @@ pub fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { /// The keys of the root current in view `v` while its level waits for its /// delay (UX D12: the tag is at rest until then), as the notice row's right -/// end echoes them at once: `SPC f`. +/// end echoes them at once: `SPC f`; all along while a state waits for the +/// keyboard (`waits`), whose head and band stay where the level would show. pub fn pending(p: *const Pardes, v: *const View, buf: []u8) ?[]const u8 { - if (v.tag_state.kind != .rest or shown(p, v)) return null; + if (if (v.tag_state.kind == .rest) shown(p, v) else !v.tag_state.waits) return null; const cur = current(p, v) orelse return null; return bindings.chord(cur.root, cur.path, buf); } @@ -1389,7 +1399,7 @@ test "a dump's tag state that indexes past what it names is at rest when loaded, try std.testing.expect(s.kind == .rest); } -test "a click that gives the keyboard to another pane ends a level as Esc does; one in the level's own tag ends it too, then does what it does there at rest: B1 gives the tag the keyboard, B2 runs the word (UX DESIGN M3)" { +test "a click that gives the keyboard to another pane ends a level as Esc does; one in the level's own tag ends it too, then does what it does there at rest; Help and a text prompt, which hold a field, wait instead, and a word run in their pane's tag leaves them up (UX DESIGN M3, O2)" { const config = @import("config.zig"); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); defer p.deinit(); @@ -1422,15 +1432,17 @@ test "a click that gives the keyboard to another pane ends a level as Esc does; click(p, word, rl.y); try std.testing.expect(hostOf(p) == null and p.view().prefix == .none); try std.testing.expectEqual(Pane.Focus.tag, p.panes[low].?.focus); - // Help, a typing state: B2 on the word ends it, then runs the word. + // Help, which holds a field: B2 on the word runs it, Help up. p.panes[low].?.focus = .body; for (" ?") |c| p.update(.{ .key = .{ .cp = c } }); try std.testing.expect(p.view().tag_state.kind == .help and hostOf(p) == low); const wrapped = p.settings.wrap; p.update(.{ .mouse = .{ .button = .middle, .kind = .press, .col = word, .row = rl.y } }); p.update(.{ .mouse = .{ .button = .middle, .kind = .release, .col = word, .row = rl.y } }); - try std.testing.expect(p.view().tag_state.kind == .rest and hostOf(p) == null); + try std.testing.expect(p.view().tag_state.kind == .help and hostOf(p) == low); try std.testing.expect(p.settings.wrap != wrapped); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(p.view().tag_state.kind == .rest); // SPC's level again, for the clicks elsewhere. p.update(.{ .key = .{ .cp = ' ' } }); p.advance(p.clock.now_ns); @@ -1453,7 +1465,19 @@ test "a click that gives the keyboard to another pane ends a level as Esc does; for (" ?") |c| p.update(.{ .key = .{ .cp = c } }); try std.testing.expect(p.view().tag_state.kind == .help); click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H); - try std.testing.expect(p.view().tag_state.kind == .rest and hostOf(p) == null); + try std.testing.expect(p.view().tag_state.kind == .help and p.view().tag_state.waits and hostOf(p) == low); + try std.testing.expectEqual(top, p.view().active); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(p.view().tag_state.kind == .rest and !p.view().tag_state.waits); + // A text prompt, `s` in the lower pane's text: it waits the same. + p.view().active = low; + p.update(.{ .key = .{ .cp = '%', .text = "%" } }); + p.update(.{ .key = .{ .cp = 's', .text = "s" } }); + try std.testing.expect(p.view().tag_state.kind == .prompt and hostOf(p) == low); + click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H); + try std.testing.expect(p.view().tag_state.kind == .prompt and p.view().tag_state.waits and hostOf(p) == low); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(p.view().tag_state.kind == .rest); } test "a rolled level that wraps has its hints on its last row at every width that leaves it a row to spare: `]` and `g` as SPC (UX D3)" { diff --git a/core/Trail.zig b/core/Trail.zig index f6cfec9a..6bed619b 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -242,6 +242,9 @@ pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { /// pane is held, as Keep holds it, and the step opens where a held pane's /// go, in its reader. fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { + // A step in the pane a picker asks from or previews in ends the picker + // first, as Esc does (UX DESIGN O3): the step is from its own text. + pardes.Pick.yieldFor(p, id); const pane = p.panes[id].?; if (pane.file) |f| if (std.mem.eql(u8, f.path, path)) { look.clearNavigationSelection(p, pane); diff --git a/core/draw.zig b/core/draw.zig index 3caf27ca..a94c8e60 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -521,8 +521,9 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: // In window mode the box holds the pane's letter instead of its mode. const label: ?u8 = if (p.view().window_pick != null) layout.windowLabel(p, id) else null; // A tag in a typing state is typed in: its box says so (walk UI SPEC - // §3.2), whatever the body's mode. - const typing = p.view().tag_state.kind != .rest and TagState.hostOf(p) == id; + // §3.2), whatever the body's mode; not while it waits for the keyboard + // (UX DESIGN O2). + const typing = p.view().tag_state.kind != .rest and !p.view().tag_state.waits and TagState.hostOf(p) == id; s.set(r.x, tag_y, if (label) |*letter| @as(*const [1]u8, letter) else if (typing) config.tag_insert else switch (pane.body.mode) { .normal => config.tag_normal, .insert => config.tag_insert, @@ -1065,7 +1066,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R for (0..rows) |y| joinCells(s, r.x + TAG_TEXT_INSET, y0 + @as(u16, @intCast(y)), storage[y * columns ..][0..columns], 0, r.w - TAG_TEXT_INSET, .{ .rgb = fg }); // A head typed in: its caret a bar at the field's, the keyboard's // where the pane has it. - if (head.caret) |c| if (active) { + if (head.caret) |c| if (active and !p.view().tag_state.waits) { const at = modal.positionAt(shown.text, shown.fromReal(c)); if (at.row < drawn.head) { const col = panes.File.rawDisplayCol(tab, lines[at.row], @min(at.col, lines[at.row].len)); diff --git a/core/exec.zig b/core/exec.zig index 44cfea64..a367ea94 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -979,6 +979,13 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ? var said: pardes.Kind.Buf(96) = .{}; return p.reportFailure(id, said.print("{s} is GUI-only, invalid here", .{@tagName(b)})); } + // A word that changes or closes the pane a picker asks from or + // previews in ends the picker first, as Esc does (UX DESIGN O3); then + // it runs as at rest (on nothing, the pane made for the picker gone). + switch (b) { + .Get, .Undo, .Redo, .Save, .Del, .Keep => pardes.Pick.yieldFor(p, id), + else => {}, + } // No pane at all (the window Delcol emptied): a word runs all the same, // with a stand-in that is no pane (New, Newcol, Exit are what make sense). const pane = p.panes[id] orelse (if (builtins.registry.scope(b) == .session or panes.anyPane(p) == null) panes.standIn(p) orelse return else return); diff --git a/core/keys.zig b/core/keys.zig index 05349d59..61ebaab9 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -197,6 +197,13 @@ pub fn handleKey(p: *Pardes, key: Key) void { // A root this key strikes starts its which-key delay; one it ends // takes its level away (TagState). defer TagState.follow(p); + // A key that moves the keyboard to the pane a waiting state hangs + // under (`C-w`'s pick, `SPC w k`) gives the state the keyboard back (UX + // DESIGN O2). + const keyboard = p.view().active; + defer if (p.view().tag_state.waits and p.view().window_pick == null and p.view().active != keyboard and TagState.hostOf(p) == p.view().active) { + p.view().tag_state.waits = false; + }; // A double-click is two clicks with nothing between them. p.view().last_click = null; if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key) catch |err| p.reportError(.at(p.view().active), "macro", err); @@ -229,8 +236,13 @@ pub fn handleKey(p: *Pardes, key: Key) void { return; } p.view().answering = 0; - // A tag in a typing state takes every key (TagState: Help, describe-key). - if (p.view().tag_state.kind != .rest) return tagStateKey(p, key); + // A tag in a typing state takes every key (TagState: Help, describe-key); + // one waiting for the keyboard (UX DESIGN O2) only Esc, which ends it + // first: the others go where the keyboard is. + if (p.view().tag_state.kind != .rest) { + if (!p.view().tag_state.waits) return tagStateKey(p, key); + if (hit(key, config.escape)) return TagState.toRest(p); + } Prompt.keyAtRest(p, key); @import("Pick.zig").keyAtRest(p, key); // Esc takes a hover's ghost lines away (SPEC §3.5) before anything else diff --git a/core/mouse.zig b/core/mouse.zig index 2e55ba95..dc730923 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -503,16 +503,22 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void { pub fn handleMouse(p: *Pardes, event: Mouse) void { const v = p.view(); - // A click that gives the keyboard to another pane ends the level or - // typing state of the tag out of rest as Esc does, its text's prefix - // with it (SPEC §3.4.6: only the pane with the keyboard leaves rest); - // one in its band or its own tag keeps it. + // The mouse never ends a state as a side effect (UX DESIGN O2): an + // event that gives the keyboard to another pane leaves a state with a + // field (Help, a picker, a text prompt, `:`, rename) up, waiting for it + // (TagState.waits); a level, the registers or describe-key, which hold + // no typed text, end as Esc ends them, the text's prefix with them + // (SPEC §3.4.6). The pointer's motion and the wheel move no keyboard. const host = pardes.TagState.hostOf(p); defer if (host) |was| if (v.active != was) { - const to = v.active; - v.active = was; - pardes.TagState.toRest(p); - v.active = to; + if (v.tag_state.kind != .rest and v.tag_state.kind != .describe) { + v.tag_state.waits = true; + } else { + const to = v.active; + v.active = was; + pardes.TagState.toRest(p); + v.active = to; + } }; var m = event; // A click goes somewhere else: the question it leaves unanswered is @@ -611,6 +617,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { return; } + // B1 off the head and the band gives the keyboard where it gives it at + // rest (a tag's text, a body, a header): a state with a field waits for + // it; a level, the registers and describe-key end first (UX DESIGN O2). + // B1 on them gives it back (bandPress). + if (m.kind == .press and m.button == config.select_button and host != null and bandPoint(p, mcol, mrow) == null) { + if (v.tag_state.kind != .rest and v.tag_state.kind != .describe) v.tag_state.waits = true else pardes.TagState.toRest(p); + } const hovered = paneAt(p, mcol, mrow); // any press that is NOT the execute+select chord abandons a pending @@ -726,16 +739,14 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { if (m.kind == .press) { tagline.exitHeader(p); } - // A press on a tag out of rest ends its state as Esc does, the bodies - // back, then does what a press there does at rest: the tag is drawn as - // at rest, and its words act as they do then (UX DESIGN M3). A pane made - // for a picker goes with it, and the press with it: it was the Esc. - if (m.kind == .press) if (hostTagAt(p, mcol, mrow)) |id| { - const serial = p.panes[id].?.serial; - pardes.TagState.toRest(p); - if (p.paneBySerial(serial) == null) return; + if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m, point); + // B2 or B3 on the text a picker previews lands it first, as Enter + // does: acting on that file is taking it (UX DESIGN O3); the press then + // does what it does at rest, in the file landed. + if (m.kind == .press and (m.button == config.exec_button or m.button == config.look_button)) if (hovered) |id| if (pardes.Pick.previewsAt(p, id, mrow)) { + pardes.Pick.landHere(p); + p.layOut(); }; - if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m.button, point); switch (m.button) { .none, .back, .forward => {}, // hover and navigation handled above @@ -929,18 +940,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { } } -/// The pane out of rest whose tag (its rows at rest, Band.covered) a press -/// is on: a window's layer hit, or a grid cell. -fn hostTagAt(p: *Pardes, mcol: u16, mrow: u16) ?usize { - const v = p.view(); - const id = pardes.TagState.hostOf(p) orelse return null; - if (v.pointer_tag_hit) |hit| return if (hit.kind == .pane and hit.id == id) id else null; - if (paneAt(p, mcol, mrow) != id) return null; - const pane = p.panes[id].?; - const top = p.tagTop(pane, v.rects[id]); - return if (mrow >= top and mrow < top + pardes.Band.covered(p, pane, id).tag) id else null; -} - /// A head's row (`head`) or a band's under it, drawn over the body: a /// covered row belongs to them, never to the body under it (UX DESIGN I1, /// M2). @@ -968,12 +967,30 @@ fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint { return .{ .id = id, .line = mrow - top - at.head, .col = col }; } -/// A press on a band (Band.zig), read-only text: the select button puts -/// the rows' cursor on the row it is on; execute runs the word under it -/// and look looks at it, as on a tag, the tag back at rest first. -fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void { +/// A press on a band (Band.zig), read-only text, and the wheel over it +/// (UX DESIGN O2). The select button gives a state waiting for the +/// keyboard its keyboard back (TagState.waits), puts the field's caret +/// where it is in the head's field, and the rows' cursor on the row it is +/// on. Execute runs the word under it and look looks at it, as on a tag: a +/// level back at rest first, a state with a field kept up (what the word +/// does may end it: Pick.yieldFor); B3 on a picker's row is Enter there, +/// Shift-B3 S-Enter. The wheel moves a picker's cursor or Help's. +fn bandPress(p: *Pardes, m: Mouse, point: BandPoint) void { const v = p.view(); const arena = p.scratch.allocator(); + const s = &v.tag_state; + const field = s.kind != .rest and s.kind != .describe; + if (m.button == .wheel_up or m.button == .wheel_down) { + const delta = if (m.button == .wheel_up) -config.wheel_rows else config.wheel_rows; + if (s.kind == .pick) pardes.Pick.wheel(p, delta); + if (s.kind == .help and s.nhits > 0) s.rows.at = @intCast(std.math.clamp(@as(i32, s.rows.at) + delta, 0, @as(i32, s.nhits) - 1)); + return; + } + if (m.button == config.select_button and s.waits) { + s.waits = false; + v.active = point.id; + p.panes[point.id].?.focus = .body; + } // The head's rows: the select button in its field puts the field's // caret there (UX DESIGN M6); its words run and are looked at as a // tag's. @@ -982,47 +999,41 @@ fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void { const shown = tagline.wrapTag(p.settings.tab, arena, h.text, tagline.tagWidth(p, point.id)) catch return; const text = modal.lineSlice(shown.text, point.line); const raw = panes.File.rawAtDisplay(p.settings.tab, text, point.col); - if (button == config.select_button) { + if (m.button == config.select_button) { const caret = h.caret orelse return; - const field = &v.tag_state.field; const at = shown.toReal(modal.lineStartOffset(shown.text, point.line) + modal.graphemeStart(text, raw)); - const start = caret - field.caret; - if (at >= start and at <= start + field.len) field.caret = @intCast(at - start); + const start = caret - s.field.caret; + if (at >= start and at <= start + s.field.len) s.field.caret = @intCast(at - start); return; } - if (button != config.exec_button and button != config.look_button) return; + if (m.button != config.exec_button and m.button != config.look_button) return; const b = tagline.wordBoundsAtCol(text, raw) 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 (!field) pardes.TagState.toRest(p); + return exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, point.id, "", 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; + 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; + if (m.button == config.select_button) { for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) { - pardes.TagState.point(p, part.row.index); + if (s.kind == .pick) pardes.Pick.press(p, part.row, false, false) else pardes.TagState.point(p, part.row.index); }; return; } - if (button != config.exec_button and button != config.look_button) return; - const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return; - const kept = arena.dupe(u8, word) catch return; - // A picker's band: B2 runs the word with the picker live (an act's word - // acts, Pick.execWord); B3 on a row lands on it. - if (v.tag_state.kind == .pick) { - if (button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", kept); - 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; - for (ln.parts) |part| if (point.col >= part.col and point.col < part.col + part.width) { - pardes.TagState.point(p, part.row.index); - return pardes.Pick.landHere(p); + if (m.button != config.exec_button and m.button != config.look_button) return; + // A picker's band: B3 on a row is Enter there (Pick.press); B2 runs the + // word under it with the picker up (an act's word acts, Pick.execWord). + if (s.kind == .pick and m.button == config.look_button) { + for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) { + return pardes.Pick.press(p, part.row, true, m.shift); }; return; } - pardes.TagState.toRest(p); - exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", kept); + const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return; + const kept = arena.dupe(u8, word) catch return; + if (s.kind != .pick) pardes.TagState.toRest(p); + exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, point.id, "", kept); } /// Index of the pane pair in column `c` whose seam (see seamRowOf) is screen @@ -2068,3 +2079,223 @@ test "one column's words at the window row's left and the window's at its right clickAt(p, .middle, row.words + @as(u16, "Find Grep ".len) + 2, 0); try std.testing.expectEqual(@as(usize, 2), p.view().ncol); } + +/// A picker asked from a held pane with three places in `dir`'s files, +/// previewed in a reader made under it (UX DESIGN O1): the asker's id. +fn heldPicker(p: *Pardes, tmp: *std.testing.TmpDir) !usize { + for ([_][]const u8{ "one.zig", "two.zig", "three.zig" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "const a = 1;\nconst b = 2;\nconst c = 3;\nconst d = 4;\n" }); + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + _ = try p.setTestFile("held\n"); + const held = p.view().active; + pardes.Trail.keep(p.panes[held].?); + var rows: [3 * (std.Io.Dir.max_path_bytes + 32)]u8 = undefined; + const list = try std.fmt.bufPrint(&rows, "{s}/one.zig:2:1 Wrap b\n{s}/two.zig:3:1 c\n{s}/three.zig:4:1 d\n", .{ dir, dir, dir }); + pardes.Pick.open(p, held, .list, "Refs", "", list); + p.update(.tick); + p.sync(); + return held; +} + +/// Screen row `i` of the band under pane `id`'s head, and a column on its +/// rows' text. +fn bandRow(p: *Pardes, id: usize, i: u16) [2]u16 { + const r = p.view().rects[id]; + const at = pardes.Band.covered(p, p.panes[id].?, id); + return .{ r.x + TAG_TEXT_INSET + 8, r.y + at.tag + at.head + i }; +} + +test "the mouse never ends a picker as a side effect (UX DESIGN O2): the pointer's motion and the wheel anywhere leave it up; the wheel over its rows moves its cursor `wheel_rows` and the preview follows; B1 on a row puts the cursor there and keeps the keyboard in the field; B2 or B3 on the preview's text lands it first; Shift-B3 on a row opens it below" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const pk = pardes.Pick.live(p).?; + const reader = p.paneBySerial(pk.landing).?; + try std.testing.expect(reader != held and pk.made); + const s = &p.view().tag_state; + const rr = p.view().rects[reader]; + // Motion and the wheel over the reader, over the held pane's body, and + // over the window row: nothing ends. + for ([_][2]u16{ .{ rr.x + 6, rr.y + 3 }, .{ 6, 0 } }) |at| { + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = at[0], .row = at[1] } }); + p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = at[0], .row = at[1] } }); + try std.testing.expect(pardes.Pick.live(p) == pk and !s.waits); + } + try std.testing.expectEqual(held, p.view().active); + // The wheel over the rows: the cursor down, the next row previewed on + // the frame after. + const row0 = bandRow(p, held, 0); + p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = row0[0], .row = row0[1] } }); + try std.testing.expectEqual(@as(u16, config.wheel_rows), s.rows.at); + p.update(.tick); + try std.testing.expect(std.mem.endsWith(u8, p.panes[reader].?.file.?.path, "two.zig")); + p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = row0[0], .row = row0[1] } }); + try std.testing.expectEqual(@as(u16, 0), s.rows.at); + // B1 on the third row: the cursor there, the picker up, the keyboard + // its field's. + const row2 = bandRow(p, held, 2); + clickAt(p, .left, row2[0], row2[1]); + try std.testing.expect(pardes.Pick.live(p) == pk and !s.waits); + try std.testing.expectEqual(@as(u16, 2), s.rows.at); + try std.testing.expectEqual(held, p.view().active); + p.update(.{ .key = .{ .cp = pardes.Key.up } }); + try std.testing.expectEqual(@as(u16, 1), s.rows.at); + p.update(.{ .key = .{ .cp = pardes.Key.down } }); + p.update(.tick); + p.sync(); + // B3 on the preview's text: it lands first, the held pane's reader + // showing that file at that line, the picker gone. + const r2 = p.view().rects[reader]; + try std.testing.expect(std.mem.endsWith(u8, p.panes[reader].?.file.?.path, "three.zig")); + clickAt(p, .right, r2.x + config.GUTTER + 6, r2.y + p.panes[reader].?.tag_rows); + try std.testing.expect(pardes.Pick.live(p) == null); + const landed = pardes.Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expect(std.mem.endsWith(u8, p.panes[landed].?.file.?.path, "three.zig")); + // Shift-B3 on a row: that place in a new pane below. + p.view().active = held; + var n: usize = 0; + for (p.panes) |slot| n += @intFromBool(slot != null); + pardes.Pick.open(p, held, .list, "Refs", "", pk.rows); + p.sync(); + const first = bandRow(p, held, 0); + p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = first[0], .row = first[1], .shift = true } }); + p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = first[0], .row = first[1], .shift = true } }); + try std.testing.expect(pardes.Pick.live(p) == null); + var now: usize = 0; + for (p.panes) |slot| now += @intFromBool(slot != null); + try std.testing.expectEqual(n + 1, now); + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "one.zig")); +} + +test "B1 in another pane: a picker waits (UX DESIGN O2), unrolled as it was, its box its pane's mode and no caret in its field; keys go where the keyboard is; B1 on its head, or C-w back to its pane, gives it the keyboard; Esc anywhere ends it first, then the pane's own Esc" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const pk = pardes.Pick.live(p).?; + const reader = p.paneBySerial(pk.landing).?; + const s = &p.view().tag_state; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // B1 on the preview: the keyboard there, the picker waiting. + const rr = p.view().rects[reader]; + clickAt(p, .left, rr.x + config.GUTTER + 3, rr.y + p.panes[reader].?.tag_rows + 1); + try std.testing.expectEqual(reader, p.view().active); + try std.testing.expect(pardes.Pick.live(p) == pk and s.waits); + try std.testing.expectEqual(@as(?usize, held), pardes.TagState.hostOf(p)); + const surface = try p.render(a); + const hr = p.view().rects[held]; + try std.testing.expectEqualStrings(config.tag_normal, surface.at(hr.x, hr.y).grapheme()); + try std.testing.expect(surface.cursor == null or surface.cursor.?.y >= rr.y); + // A key goes to the reader: `j` moves its caret, the field untouched. + const row = p.panes[reader].?.body.cur_row; + p.update(.{ .key = .{ .cp = 'j', .text = "j" } }); + try std.testing.expectEqual(row + 1, p.panes[reader].?.body.cur_row); + try std.testing.expectEqual(@as(u16, 0), s.field.len); + // B1 on the head: the keyboard back in the field. + const head = bandRow(p, held, 0); + clickAt(p, .left, head[0], head[1] - 1); + try std.testing.expect(!s.waits and p.view().active == held); + p.update(.{ .key = .{ .cp = 'w', .text = "w" } }); + try std.testing.expectEqualStrings("w", s.field.text()); + // C-w to the held pane from the reader gives it back too. + clickAt(p, .left, rr.x + config.GUTTER + 3, rr.y + p.panes[reader].?.tag_rows + 1); + try std.testing.expect(s.waits); + p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); + p.update(.{ .key = .{ .cp = 'k', .text = "k" } }); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + try std.testing.expect(!s.waits and p.view().active == held and pardes.Pick.live(p) == pk); + // The keyboard to the held pane's own text under the band, in insert + // mode; Esc ends the picker first, the text still inserting; the next + // Esc is the text's. + const at = pardes.Band.covered(p, p.panes[held].?, held); + clickAt(p, .left, hr.x + config.GUTTER + 3, hr.y + at.tag + at.over); + try std.testing.expect(s.waits and p.view().active == held); + p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); + try std.testing.expect(p.panes[held].?.body.mode == .insert); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(pardes.Pick.live(p) == null and s.kind == .rest and !s.waits); + try std.testing.expect(p.panes[held].?.body.mode == .insert); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(p.panes[held].?.body.mode == .normal); +} + +test "B1 on the asking pane's own tag: the picker waits, the tag's text has the keyboard; a word there that changes nothing leaves it up; B2 Del ends it first, as Esc does, and closes the pane (UX DESIGN O2, O3)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const s = &p.view().tag_state; + p.panes[held].?.tag.own = try p.gpa.dupe(u8, "Wrap"); + p.sync(); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const tag = try tagline.tagText(p, frame.allocator(), p.panes[held].?); + const hr = p.view().rects[held]; + const col = struct { + fn of(q: *Pardes, t: []const u8, x: u16, word: []const u8) u16 { + return x + TAG_TEXT_INSET + 1 + @as(u16, @intCast(panes.File.displayWidth(q.settings.tab, t[0..std.mem.indexOf(u8, t, word).?]))); + } + }.of; + clickAt(p, .left, col(p, tag, hr.x, "Wrap"), hr.y); + try std.testing.expect(pardes.Pick.live(p) != null and s.waits); + try std.testing.expectEqual(Pane.Focus.tag, p.panes[held].?.focus); + const wrapped = p.settings.wrap; + clickAt(p, .middle, col(p, tag, hr.x, "Wrap"), hr.y); + try std.testing.expect(p.settings.wrap != wrapped and pardes.Pick.live(p) != null); + var n: usize = 0; + for (p.panes) |slot| n += @intFromBool(slot != null); + clickAt(p, .middle, col(p, tag, hr.x, "Del"), hr.y); + try std.testing.expect(pardes.Pick.live(p) == null and s.kind == .rest); + try std.testing.expect(p.panes[held] == null); + var now: usize = 0; + for (p.panes) |slot| now += @intFromBool(slot != null); + // The held pane and the reader made for the picker, both gone. + try std.testing.expectEqual(n - 2, now); +} + +test "the act step and the rows under the mouse (UX DESIGN O2): B2 on an act's word acts and the picker stays, B2 on a row's word runs it and the picker stays, B1 on an act puts the act step's cursor on it" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const pk = pardes.Pick.live(p).?; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // B2 on `Wrap` in the first row's text. + const band = (try pardes.Band.of(p, a, p.panes[held].?, held)).?; + const ln = try band.line(a, p.settings.tab, 0); + const r = p.view().rects[held]; + const top = bandRow(p, held, 0)[1]; + const wrap_col: u16 = r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, ln.text[0..std.mem.indexOf(u8, ln.text, "Wrap").?]))) + 1; + const wrapped = p.settings.wrap; + clickAt(p, .middle, wrap_col, top); + try std.testing.expect(p.settings.wrap != wrapped and pardes.Pick.live(p) == pk); + // M-l: the act step; B1 on `Copy` puts its cursor there, B2 on it + // copies the place, the picker up. + p.update(.{ .key = .{ .cp = 'l', .alt = true } }); + _ = frame.reset(.retain_capacity); + const acts = (try pardes.Band.of(p, a, p.panes[held].?, held)).?; + var copy: ?[2]u16 = null; + for (0..acts.height) |y| { + const l = try acts.line(a, p.settings.tab, @intCast(y)); + if (std.mem.indexOf(u8, l.text, "y Copy")) |at| copy = .{ r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, l.text[0..at]))) + 3, top + @as(u16, @intCast(y)) }; + } + clickAt(p, .left, copy.?[0], copy.?[1]); + try std.testing.expect(pk.spine == .acts and pardes.Pick.live(p) == pk); + try std.testing.expectEqual(@as(u8, 6), pk.act_at); + clickAt(p, .middle, copy.?[0], copy.?[1]); + try std.testing.expect(pardes.Pick.live(p) == pk); + try std.testing.expect(std.mem.endsWith(u8, p.registers.text(p.gpa, pardes.Registers.default).?, "one.zig:2\n")); +} diff --git a/core/panes.zig b/core/panes.zig index 16b1d388..f4f528b7 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1495,6 +1495,9 @@ pub fn paneDir(pane: *const Pane) []const u8 { /// none by recency. pub fn removePane(p: *Pardes, id: usize, to: ?usize) error{OutOfMemory}!void { const v = p.view(); + // The pane a picker asks from or previews in: the picker ends first, + // as Esc ends it (UX DESIGN O3), a pane made for it gone with it. + pardes.Pick.yieldFor(p, id); const pane = p.panes[id] orelse return; // What is docked to it closes with it, first, each giving its rows // back to it: then its rows, theirs among them, go where a pane's go. -- cgit v1.3 From 75534de566388fe8dcb17b8257d535c680ae4b7d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 11:54:48 -0300 Subject: Pick, Prompt, TagState, test/process: the act/source row goes, and every head row ends with its count and at most one dim hint, the one key to what the head and the band do not show; a list known at open is exactly its rows tall (UX DESIGN O4, binding; the user, on W5's field under the tag: "why so many builtins are shown below still? most of them don't make much sence in the picker context right? also why other pickers names are there? that's wayyyyy to crowded, we only want to keep the absolute necessary there"); THE WAY IT WAS: Pick.head put a second row under every picker's head, under the spines, `Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist …` (the acts, then the other sources' words, cut with `…`), the head row's right block carried up to 43 cells of hints (`⏎ land · M-⏎ as a list · C-r history · esc`, `↑ roll up · ? field · esc`, `⏎ wear it · esc`, `⏎ or 1-9 apply it · esc`, `⏎ rename · esc`, `⏎ run · esc`), and Pick.bandRows held 4 rows at least (D6's 4 counted the act row), a Grep's and All's 11 from the first frame whatever they found; THE CHANGE: Pick.head is one row, the count and `M-l acts` (dim, dropped first when the row is narrow; none for Themes, code actions and Lists, which have no acts); the acts stay on their keys and in the act step (M-l, M-Enter), each source on its own leader key, M-h's spine switching with the query kept, and any word typed into a tag still runs (Pick.execWord: `Grep`, `Split`); every text prompt and `:` hints `C-r history` (Prompt's table loses its `hint` column: one const), a rolled or unrolled level and the registers `? help`, describe-key keeps its question `press a key or a sequence` (its `· esc` and a found key's `⏎ run · esc` go), rename none; Pick.bandRows: a list known at open (Panes, Recent, Jumplist, a list, Messages, Themes, code actions, Lists) exactly its rows (1 at least, 11 and the cap at most), one whose rows come later (Find, Grep, All, Symbols) 3 at least and growing as they come, never shrinking while it is up: `tall`, a picker's most rows since it unrolled (a new field, reset by unroll, raised in produceAll a step at a time: in the dump and the digest), so typing a Grep's query never moves the body; RUN (TEST FIRST): Pick "a picker's head is one row: the count and one dim hint at its right end, `M-l acts`; no row of acts and sources, the list's rows right under it; Themes hints nothing" (replaces the act-row test; fails on the change before at Pick.zig:3979, the head two rows) and Pick "a picker's band is its list's rows (UX DESIGN O4, D6): a list whose rows come later (Find) holds 3 at open, never moved by typing; a list known at open exactly its rows: SPC b b with two panes covers its head and 2 rows" (was "… 4 rows at least …"; fails on the change before, 4 rows for 3), pass now; the tests that read the old hints read the new ones (TagState's right block, at 14 columns now where `? help` no longer fits, its rolled-level and wrapping tests, Band's SPC Down, draw's dim-hint ink, Prompt's `/ ? s K |` heads, Command's `:`), Pick's 40 % test lets the Grep's lines come (the clock to the pause's end: 40 lines, the band from 3 to its cap), and views' short-column test runs at 40x14 (at 40x15 the band, a row shorter, now fits whole); a user saw the crowded row under every picker and the long hints on every head; the process cases that wait for a rolled level wait for its `? help` (tty_boot leader twice, tty_editing find; they waited for `↓ unroll`); GATES (Debug tui): core-test 1172/1346 (174 skipped; one program's 7 cached), shell-test 1387/1390 (3 skipped); process-test 7 of 149 failed (3 skipped): pipe, msg, selregex, fsearch, lsp on their goldens, leader and find on the old wait, the goldens re-recorded by the next change; the dump changes (Pick.tall, and the change before's TagState.waits): the dump fuzz and the soak with the next change; load 1.4 to 4.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 2 +- core/Command.zig | 2 +- core/Pick.zig | 138 +++++++++++++++++++++---------------------- core/Prompt.zig | 58 +++++++++--------- core/TagState.zig | 26 ++++---- core/draw.zig | 4 +- core/views.zig | 10 ++-- test/process/tty_boot.zig | 4 +- test/process/tty_editing.zig | 2 +- 9 files changed, 121 insertions(+), 125 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Band.zig b/core/Band.zig index 5efe1a36..1a1a9b48 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -894,7 +894,7 @@ test "SPC Down unrolls the level into a band under the tag's text, drawn over th // The head, the layer's first row, names the level and says how to roll // it up. const head = (try TagState.head(p, frame.allocator(), pane)).?.text; - try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ↑ roll up · ? field · esc")); + try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ? help")); try std.testing.expect(std.mem.startsWith(u8, try layerRow(frame.allocator(), layer, 0), "␣ SPC ")); // Down moves the cursor; Up back to the first row, then rolls up. p.update(.{ .key = .{ .cp = Key.down } }); diff --git a/core/Command.zig b/core/Command.zig index 691f7dfa..afc3790d 100644 --- a/core/Command.zig +++ b/core/Command.zig @@ -759,7 +759,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqual(Prompt.Op.command, s.prompt.op); try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus); // The head: its key cell, the field, the count, the hints. - try std.testing.expect(has(try headOf(p), ": 18 commands Tab complete · ⏎ run · C-r history · esc")); + try std.testing.expect(has(try headOf(p), "18 commands C-r history")); // The rows: the tag's words in its order, `in the tag`, the last ruled // off; then the commands, each what it takes. try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save ")); diff --git a/core/Pick.zig b/core/Pick.zig index 7bceab39..2637bb1d 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -106,6 +106,10 @@ made: bool = false, cap: u16 = 0, /// Unrolled in a view's tag now. unrolled: bool = false, +/// The most rows its list has had since it unrolled, eleven at most: its +/// band grows with a list whose rows come later and never shrinks while it +/// is up (bandRows, UX D6). +tall: u8 = 0, names: Names = .{}, /// A Grep's lines, as the disk engine sends them (Query.take). found: std.ArrayList(Query.Found) = .empty, @@ -414,6 +418,7 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { s.field.set(query); s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; + pk.tall = 0; pk.shown = no_row; pk.previewed = false; // The whole window previews a theme. @@ -595,6 +600,7 @@ fn toBest(p: *Pardes, pk: *Pick) void { /// current row. pub fn produceAll(p: *Pardes, tick: bool) void { for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { + pk.tall = @intCast(@max(pk.tall, @min(have(p, pk), Band.Cursor.shown))); if (pk.names.busy()) { // A cursor on the best match follows it while the rest are // scored. @@ -608,6 +614,12 @@ pub fn produceAll(p: *Pardes, tick: bool) void { }; } +/// The rows a picker's source has: every name it scores (not what the +/// query keeps), a Grep's lines and All's places for this query. +fn have(p: *const Pardes, pk: *const Pick) usize { + return if (fuzzy(pk)) pk.names.cands.items.len else count(p, pk); +} + /// The frames a live picker still owes: scoring, a preview (nextWake's). pub fn busy(p: *const Pardes) bool { for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { @@ -813,10 +825,11 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me // ---- the tag ---- -/// The head under the landing pane's tag (SPEC §5.3, UX DESIGN M2): the +/// The head under the asking pane's tag (SPEC §5.3, UX DESIGN M2, O1): the /// key cells, the source's word, the query, the count `cursor/total` and -/// `•marked`; on a second row the acts and the other sources' words, under -/// spines from the key cells. +/// `•marked`, and one hint, `M-l acts`, the key to the acts (UX DESIGN O4: +/// no row of acts and sources; each source has its own key, M-h switches +/// keeping the query). pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const pk = live(p) orelse return null; const s = &p.view().tag_state; @@ -839,65 +852,29 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { if (n == 0) try text.append(arena, '0') else try text.print(arena, "{d}/{d}", .{ s.rows.at + 1, n }); if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len}); if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯"); - // Themes, actions and Lists have no acts and no other sources: no - // second row. - if (pk.source == .themes or pk.source == .actions or pk.source == .lists) { - const hints = text.items.len; - try b.styled(switch (pk.source) { - .themes => "⏎ wear it · esc", - .lists => "⏎ reopen it · esc", - else => "⏎ or 1-9 apply it · esc", - }, .dim); - try b.right(counted, hints); - var h = b.done(); - h.caret = caret; - return h; - } - try b.right(counted, text.items.len); - // The second row, one row (UX D2): under the spines from the key - // cells, from two cells right of the last, the acts, `|`, the other - // sources' words, each switching to it, the `|` and the sources dim - // (UX D4); what does not fit is dropped from the right (the sources - // first) and the row ends in a dim `…` (M-l and M-h reach them all). - try b.row(if (b.ncols > 0) b.cols[b.ncols - 1] + 2 else 0); - var offer: [acts.len + 1 + std.enums.values(Source).len][]const u8 = undefined; - var nw: usize = 0; - for (acts) |act| if (offered(pk, act)) { - offer[nw] = act.word; - nw += 1; - }; - const nacts = nw; - offer[nw] = "|"; - nw += 1; - inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != .lists and src != pk.source) { - offer[nw] = words.get(src).word; - nw += 1; - }; - for (offer[0..nw], 0..) |word, i| { - const gap: usize = @intFromBool(i > 0); - const rest: usize = if (i + 1 < nw) 2 else 0; - if (b.col() + gap + File.displayWidth(p.settings.tab, word) + rest > b.width) { - try b.put(if (gap > 0) " " else ""); - try b.styled("…", .dim); - break; - } - try b.put(if (gap > 0) " " else ""); - if (i >= nacts) try b.styled(word, .dim) else try b.put(word); - } + // Themes, code actions and Lists have no acts: no hint. + const hints = text.items.len; + if (pk.source != .themes and pk.source != .actions and pk.source != .lists) try b.styled("M-l acts", .dim); + try b.right(counted, hints); var h = b.done(); h.caret = caret; return h; } -/// The band's rows (UX D6): as many as the list will show, from what the -/// source has (not what the query keeps: typing never moves the body), -/// four at least, eleven at most, and its `cap` at most (the host pane's -/// 40 % at open: the layout asks this while it lays the column out, when -/// no pane has its rows yet). +/// The band's rows (UX D6, DESIGN O4): as many as the list will show, from +/// what the source has (not what the query keeps: typing never moves the +/// body) and the most it has had (`tall`): a list known at open exactly its +/// rows, one whose rows come later (Find, Grep, All, Symbols) three at +/// least, growing as they come; eleven at most, and its `cap` at most (the +/// asking pane's 40 % at open: the layout asks this while it lays the +/// column out, when no pane has its rows yet). pub fn bandRows(p: *const Pardes) u16 { const pk = live(p) orelse return 0; - const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len; - const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), pk.cap)); + const later: usize = switch (pk.source) { + .find, .grep, .all, .symbols => 3, + else => 1, + }; + const rows: usize = @max(1, @min(Band.Cursor.shown, @max(later, pk.tall, have(p, pk)), pk.cap)); // Its second step's rows too: the sources, the acts and what they act on. return @intCast(switch (pk.spine) { .sources => @max(rows, spine_rows.len), @@ -2326,7 +2303,7 @@ test "a picker from a held pane hangs under that pane's tag, which keeps the key try std.testing.expectEqualStrings("pick", pk.query.slice()); } -test "a picker's act row is one row under the spines, two cells right of the last: what does not fit dropped from the right, the sources first, a dim `…` ending it" { +test "a picker's head is one row: the count and one dim hint at its right end, `M-l acts`; no row of acts and sources, the list's rows right under it; Themes hints nothing (UX DESIGN O4)" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 40 }); defer p.deinit(); p.settings.jumps = .walk; @@ -2337,25 +2314,31 @@ test "a picker's act row is one row under the spines, two cells right of the las _ = try p.setTestFile("held\n"); const asker = p.view().active; Trail.keep(p.panes[asker].?); + p.gpa.free(p.panes[asker].?.file.?.path); + 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; open(p, asker, .find, "", "", ""); - const reader = asker; + settle(p); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - const tag = try headOf(p, a, reader); - var rows = std.mem.splitScalar(u8, tag, '\n'); - try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find ")); - const acts_row = rows.next().?; - try std.testing.expect(rows.next() == null); - try std.testing.expect(std.mem.startsWith(u8, acts_row, "│ │ Walk Look ")); - try std.testing.expect(std.mem.endsWith(u8, acts_row, " …")); - try std.testing.expect(File.displayWidth(p.settings.tab, acts_row) <= pardes.tagline.tagWidth(p, reader)); - const h = (try head(p, a, p.panes[reader].?)).?; + const tag = try headOf(p, a, asker); + try std.testing.expect(std.mem.indexOfScalar(u8, tag, '\n') == null); + try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find ") and std.mem.endsWith(u8, tag, "1/1 M-l acts")); + try std.testing.expectEqual(@as(usize, pardes.tagline.tagWidth(p, asker)), File.displayWidth(p.settings.tab, tag)); + const h = (try head(p, a, p.panes[asker].?)).?; try std.testing.expect(h.spans[h.spans.len - 1].style == .dim); + // The band's first row the list's first. + const band = (try Band.of(p, a, p.panes[asker].?, asker)).?; + try std.testing.expect(std.mem.indexOf(u8, (try band.line(a, p.settings.tab, 0)).text, "▶ alpha.zig") != null); + p.update(.{ .key = .{ .cp = Key.escape } }); + open(p, asker, .themes, "", "", ""); + const themes = try headOf(p, a, asker); + try std.testing.expect(std.mem.indexOf(u8, themes, "esc") == null and std.mem.indexOf(u8, themes, "M-l") == null and std.mem.indexOf(u8, themes, "⏎") == null); + p.update(.{ .key = .{ .cp = Key.escape } }); } -test "a picker's band is sized from its list at open, 4 rows at least, and typing never moves it" { +test "a picker's band is its list's rows (UX DESIGN O4, D6): a list whose rows come later (Find) holds 3 at open, never moved by typing; a list known at open exactly its rows: SPC b b with two panes covers its head and 2 rows" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); p.settings.jumps = .walk; @@ -2375,13 +2358,23 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin 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. - try std.testing.expectEqual(@as(u16, 4), rows); + // One file listed: three rows, ground under it. + try std.testing.expectEqual(@as(u16, 3), 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, Band.covered(p, p.panes[reader].?, reader).band); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Two panes: SPC b b's band two rows. + p.newScratchBelow(asker); + p.view().active = asker; + p.sync(); + for (" bb") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.sync(); + try std.testing.expectEqual(Source.panes, live(p).?.source); + const at = Band.covered(p, p.panes[asker].?, asker); + try std.testing.expect(at.head == 1 and at.band == 2); } 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)" { @@ -2407,7 +2400,10 @@ test "a picker's band is capped once at open at 40 % of its asking pane's rows; const reader = p.paneBySerial(live(p).?.landing).?; try std.testing.expect(reader != asker); for ("pub fn") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + // Its lines after the typing's pause: the band from 3 rows to its cap. + if (p.stream.due_ns) |due| p.clock.now_ns = due; settle(p); + try std.testing.expectEqual(@as(usize, 40), count(p, live(p).?)); p.update(.{ .key = .{ .cp = Key.down } }); p.update(.tick); p.sync(); @@ -2447,7 +2443,7 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const refs = try headOf(p, frame.allocator(), id); - try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.indexOf(u8, refs, " 3/4 •1\n") != null); + try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.endsWith(u8, refs, " 3/4 •1 M-l acts")); p.update(.{ .key = .{ .cp = 'a', .alt = true } }); try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len); p.update(.{ .key = .{ .cp = 'a', .alt = true } }); @@ -2466,7 +2462,7 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and try std.testing.expectEqual(@as(usize, 1), count(p, pk)); _ = frame.reset(.retain_capacity); const refined = try headOf(p, frame.allocator(), id); - try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.indexOf(u8, refined, " 1/1\n") != null); + try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.endsWith(u8, refined, " 1/1 M-l acts")); // Backspace twice: the `w` goes, then the refinement, its query back. p.update(.{ .key = .{ .cp = Key.backspace } }); p.update(.{ .key = .{ .cp = Key.backspace } }); diff --git a/core/Prompt.zig b/core/Prompt.zig index e9c231da..d5f9a374 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -124,24 +124,28 @@ pub const Ring = struct { const Info = struct { /// Its key cell. cell: []const u8, - hint: []const u8, }; const info = std.EnumArray(Op, Info).init(.{ - .search = .{ .cell = "/", .hint = "⏎ land · M-⏎ as a list · C-r history · esc" }, - .search_back = .{ .cell = "?", .hint = "⏎ land · M-⏎ as a list · C-r history · esc" }, - .select = .{ .cell = "s", .hint = "⏎ select · M-⏎ as a list · C-r history · esc" }, - .split = .{ .cell = "S", .hint = "⏎ select · M-⏎ as a list · C-r history · esc" }, - .keep = .{ .cell = "K", .hint = "⏎ keep · M-⏎ as a list · C-r history · esc" }, - .remove = .{ .cell = "A-K", .hint = "⏎ keep · M-⏎ as a list · C-r history · esc" }, - .pipe = .{ .cell = "|", .hint = "⏎ replace · C-r history · esc" }, - .pipe_to = .{ .cell = "A-|", .hint = "⏎ run · C-r history · esc" }, - .insert = .{ .cell = "!", .hint = "⏎ insert · C-r history · esc" }, - .append = .{ .cell = "A-!", .hint = "⏎ append · C-r history · esc" }, - .keep_pipe = .{ .cell = "$", .hint = "⏎ keep · C-r history · esc" }, - .command = .{ .cell = ":", .hint = "Tab complete · ⏎ run · C-r history · esc" }, + .search = .{ .cell = "/" }, + .search_back = .{ .cell = "?" }, + .select = .{ .cell = "s" }, + .split = .{ .cell = "S" }, + .keep = .{ .cell = "K" }, + .remove = .{ .cell = "A-K" }, + .pipe = .{ .cell = "|" }, + .pipe_to = .{ .cell = "A-|" }, + .insert = .{ .cell = "!" }, + .append = .{ .cell = "A-!" }, + .keep_pipe = .{ .cell = "$" }, + .command = .{ .cell = ":" }, }); +/// Every prompt's one hint (UX DESIGN O4): the key to what its head and +/// band do not show. Enter's verb is the head's own `= Look /dirty/`; +/// M-Enter and Tab are in Help; Esc is never hinted. +const hint = "C-r history"; + /// The history `op` reads and Enter adds to. fn ring(p: *Pardes, op: Op) *Ring { return switch (op) { @@ -1097,7 +1101,7 @@ fn strike(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, line: i32, lo_: } /// The head of the prompt's tag: `s self▌ = Exec Edit x/self/ 4 -/// selections in 6 lines ⏎ select · M-⏎ as a list · C-r history · esc`. +/// selections in 6 lines C-r history`. pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { const s = &p.view().tag_state; const pr = &s.prompt; @@ -1139,7 +1143,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { } if (pr.op == .command) try Command.count(p, arena, text); const hints = text.items.len; - const hint = info.get(pr.op).hint; if (tail) |t| { // Both beside the count, or neither: as much room as the right // block asks for its two gaps (Builder.right drops the hints alone). @@ -1402,9 +1405,10 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind); // No chip on the notice band: the prompt is the tag's. try std.testing.expectEqual(Pane.Prompt.none, pane.prompt); - try std.testing.expect(has(try headOf(p), "s ⏎ select · M-⏎ as a list · C-r history · esc")); + // Its one hint at the row's end (UX DESIGN O4). + try std.testing.expect(std.mem.startsWith(u8, try headOf(p), "s ") and std.mem.endsWith(u8, try headOf(p), " C-r history")); typeKeys(p, "self"); - try std.testing.expect(has(try headOf(p), "s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); + try std.testing.expect(has(try headOf(p), "s self = Exec Edit x/self/ ") and has(try headOf(p), "2 selections in 3 lines C-r history")); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); try std.testing.expect(selecting(p, pane).?.dim == false); // No match: 0, and the selection it began with. @@ -1447,7 +1451,7 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba try std.testing.expect(has(try headOf(p), "K self.. = Exec Edit g/self../ keeps 2 of 2")); p.update(.{ .key = .{ .cp = Key.down } }); typeKeys(p, "b"); - try std.testing.expect(has(try headOf(p), "K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep")); + try std.testing.expect(has(try headOf(p), "K b = Exec Edit g/b/ ") and has(try headOf(p), "keeps 1 of 2 C-r history")); // Ctrl-r: the history under the tag, a row a line. p.update(.{ .key = .{ .cp = 'r', .ctrl = true } }); try std.testing.expectEqual(@as(u16, 1), Band.takes(p, p.view().active)); @@ -1459,7 +1463,7 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba typeKeys(p, "|"); try std.testing.expectEqual(Pane.Prompt.none, pane.prompt); p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); - try std.testing.expect(has(try headOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); + try std.testing.expect(has(try headOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ") and has(try headOf(p), "⋯ C-r history")); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqualStrings("tr a-z A-Z", p.registers.value('|', 0).?); var asked: ?u32 = null; @@ -1496,7 +1500,7 @@ test "/ searches the body as it is typed: the current place selected, `▸` in t pane.body.cur_row = 2; pane.body.cur_col = 6; typeKeys(p, "/dirty"); - try std.testing.expect(has(try headOf(p), "/ dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list")); + try std.testing.expect(has(try headOf(p), "/ dirty = Look /dirty/ ") and has(try headOf(p), "3/7 · 5 lines C-r history")); try std.testing.expectEqual(@as(?usize, 2), pane.places.current); // (Its first row under the head's, UX DESIGN M2.) try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1)); @@ -1554,9 +1558,9 @@ test "? searches back from the caret; no match is 0; a pattern that is no regex pane.body.cur_col = 6; const was = pane.body.primaryRange(pane.file.?.content, 0); typeKeys(p, "?dirty"); - try std.testing.expect(has(try headOf(p), "? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land")); + try std.testing.expect(has(try headOf(p), "? dirty = Look ?dirty? ") and has(try headOf(p), "2/7 · 5 lines C-r history")); typeKeys(p, "x"); - try std.testing.expect(has(try headOf(p), "= Look ?dirtyx? 0 ⏎ land")); + try std.testing.expect(has(try headOf(p), "= Look ?dirtyx? ") and has(try headOf(p), "0 C-r history")); try std.testing.expectEqualDeep(was, pane.body.primaryRange(pane.file.?.content, 0)); p.update(.{ .key = .{ .cp = Key.backspace } }); typeKeys(p, "("); @@ -1643,13 +1647,13 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho p.update(.{ .key = .{ .cp = Key.enter } }); typeKeys(p, "|"); p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); - try std.testing.expect(has(try headOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); + try std.testing.expect(has(try headOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ") and has(try headOf(p), "⋯ C-r history")); const first = lastPipe(p) orelse return error.MissingLiveRun; const asked = p.pipe.pipeRequest(first).?; try std.testing.expectEqual(@as(usize, 2), asked.inputs.len); try std.testing.expect(has(asked.command, "tr a-z A-Z") and has(asked.command, "\\036")); p.update(.{ .pipe_resp = .{ .id = first, .success = true, .outputs = &.{ "B\x1e\x1e0", "A\x1e\x1e0" } } }); - try std.testing.expect(has(try headOf(p), " 2 lines → 2 · exit 0 ⏎ replace")); + try std.testing.expect(has(try headOf(p), "2 lines → 2 · exit 0 C-r history")); // The body: each output a ghost line under the line it replaces, the // rows below pushed down; the text as it was; its first row under the // head's (UX DESIGN M2). @@ -1791,7 +1795,7 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it const h = try head(p, p.scratch.allocator(), pane); const lines = std.mem.indexOf(u8, h.text, " \u{b7} 5 lines"); if (cols == 200) { - try std.testing.expect(has(h.text, "3/7 \u{b7} 5 lines \u{23ce} land")); + try std.testing.expect(has(h.text, "3/7 \u{b7} 5 lines C-r history")); const dim = for (h.spans) |span| { if (span.lo == lines.? and span.style == .dim) break span; } else return error.TestUnexpectedResult; @@ -1799,7 +1803,7 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it } else { // No room for the hints: the count alone, at the row's end. try std.testing.expect(lines == null); - try std.testing.expect(std.mem.indexOf(u8, h.text, "\u{23ce} land") == null); + try std.testing.expect(std.mem.indexOf(u8, h.text, "C-r history") == null); try std.testing.expect(std.mem.endsWith(u8, h.text, "3/7")); } } @@ -1810,7 +1814,7 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it pane.body.cur_row = 7; pane.body.cur_col = 6; typeKeys(p, "/dirty"); - try std.testing.expect(has(try headOf(p), "1/7 \u{21bb} \u{b7} 5 lines \u{23ce} land")); + try std.testing.expect(has(try headOf(p), "1/7 \u{21bb} \u{b7} 5 lines C-r history")); } test "C-r's history has the band's cursor like any list (UX D5): `▶` on its newest line, Down and C-n, Up and C-p move it, Enter takes the line under it" { diff --git a/core/TagState.zig b/core/TagState.zig index 622cb949..9be689c0 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -730,14 +730,12 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { try b.put(" "); try b.put(c.label); }; - const hints = b.text.items.len; - try b.styled("⏎ run · esc", .dim); - try b.right(hints, hints); } else try b.put("…"); } else { + // The state's question, not a hint (UX DESIGN O4). try b.put("…"); const hints = b.text.items.len; - try b.styled("press a key or a sequence · esc", .dim); + try b.styled("press a key or a sequence", .dim); try b.right(hints, hints); } return b.done(); @@ -745,7 +743,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { .pick => return @import("Pick.zig").head(p, arena, pane), .prompt => return try Prompt.head(p, arena, pane), // `Rename`, the name under the caret struck, the new one typed: - // `Rename best → top▌ ⏎ rename · esc` (SPEC §3.5). + // `Rename best → top▌` (SPEC §3.5), no hint (UX DESIGN O4). .rename => { try b.put("Rename "); try b.styled(Ask.renamedWord(pane) orelse "", .strike); @@ -753,9 +751,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { var h = b.done(); h.caret = @intCast(b.text.items.len + s.field.caret); try b.put(s.field.text()); - const hints = b.text.items.len; - try b.styled("⏎ rename · esc", .dim); - try b.right(hints, hints); h.text = b.text.items; h.spans = b.spans.items; return h; @@ -764,10 +759,12 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { const cur = current(p, v) orelse return null; try b.keyCells(cur.root, cur.path); const node = bindings.nodeAt(cur.root, cur.path) orelse return b.done(); + // One hint, a level's and the registers' (UX DESIGN O4): `? help`. + const hint = "? help"; if (s.unrolled) { try b.put(if (cur.path.len == 0) bindings.info.get(cur.root).label else node.label); const hints = b.text.items.len; - try b.styled("↑ roll up · ? field · esc", .dim); + try b.styled(hint, .dim); try b.right(hints, hints); return b.done(); } @@ -801,7 +798,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { // level that wraps gives them its spare row, its last child going to // it to leave them room; a level of one row or of all its rows keeps // its rows, and they drop where they do not fit. - const hint = "↓ unroll · ? help"; const hinted = 2 + panes.File.displayWidth(tab, hint); var rows: usize = 1; for (level, 0..) |c, i| { @@ -966,14 +962,14 @@ test "the right block: the count `cursor/matches` at the row's right end, fixed p.update(.{ .key = .{ .cp = Key.down } }); row = firstRow(try testTag(p, a)); try std.testing.expect(std.mem.startsWith(u8, row, "␣ SPC ")); - try std.testing.expect(std.mem.endsWith(u8, row, " ↑ roll up · ? field · esc")); + try std.testing.expect(std.mem.endsWith(u8, row, " ? help")); try std.testing.expectEqual(width, panes.File.displayWidth(tab, row)); const h = (try head(p, a, p.panes[p.view().active].?)).?; const last = h.spans[h.spans.len - 1]; try std.testing.expect(last.style == .dim and last.hi == h.text.len); p.update(.{ .key = .{ .cp = Key.escape } }); // Where the row has no room for them, the hints go whole. - const narrow = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 24, .rows = 30 }); + const narrow = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 14, .rows = 30 }); defer narrow.deinit(); _ = try narrow.setTestFile("one\n"); narrow.update(.{ .key = .{ .cp = ' ' } }); @@ -1024,7 +1020,7 @@ test "a rolled level breaks between its children only: the rows after the first whole += 1; } try std.testing.expect(whole > 0 and whole < level.len); - try std.testing.expect(std.mem.endsWith(u8, rows[n - 1], try std.fmt.allocPrint(a, "+{d} ↓", .{level.len - whole}))); + try std.testing.expect(std.mem.indexOf(u8, rows[n - 1], try std.fmt.allocPrint(a, "+{d} ↓", .{level.len - whole})) != null); // A level that fits takes one row; its hints at its end where the row // has room for them, else none. p.update(.{ .key = .{ .cp = 'h' } }); @@ -1494,7 +1490,7 @@ test "a rolled level that wraps has its hints on its last row at every width tha p.clock.now_ns = p.view().tag_state.due_ns; try std.testing.expect(hostOf(p) != null); const tag = try testTag(p, a); - if (std.mem.count(u8, tag, "\n") == 1) try std.testing.expect(std.mem.endsWith(u8, tag, " ↓ unroll · ? help")); + if (std.mem.count(u8, tag, "\n") == 1) try std.testing.expect(std.mem.endsWith(u8, tag, " ? help")); p.update(.{ .key = .{ .cp = pardes.Key.escape } }); try std.testing.expect(hostOf(p) == null); }; @@ -1748,7 +1744,7 @@ test "out of rest a tag is drawn as at rest, the head hanging under it (UX DESIG const head_y: u16 = @intCast(now_y + tag_rows); const row = try gridRow(a, s, r.x + pardes.TAG_TEXT_INSET, head_y, r.w - pardes.TAG_TEXT_INSET); try std.testing.expect(std.mem.startsWith(u8, row, "␣ l Refs ")); - try std.testing.expect(std.mem.endsWith(u8, row, " 1/1")); + try std.testing.expect(std.mem.endsWith(u8, row, " 1/1 M-l acts")); // The band's first row under the head's: the list's row, its cursor's. const band_y: u16 = head_y + Band.covered(p, pane, id).head; try std.testing.expect(std.mem.indexOf(u8, try gridRow(a, s, r.x + pardes.TAG_TEXT_INSET, band_y, r.w - pardes.TAG_TEXT_INSET), "▶ near.txt:3") != null); diff --git a/core/draw.zig b/core/draw.zig index a94c8e60..de47f469 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -1908,7 +1908,7 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d const a = frame.allocator(); const roles = &p.chromeTheme().roles; const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); - // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ↓ unroll · ? help`. + // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ? help`. p.clock.now_ns = 5 * std.time.ns_per_s; p.clock.stepped_ns = p.clock.now_ns; p.update(.{ .key = .{ .cp = ' ' } }); @@ -1930,7 +1930,7 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d return null; } }; - const hint = Row.find(row, "unroll").?; + const hint = Row.find(row, "? help").?; try std.testing.expectEqual(Color{ .rgb = inks.dim }, row[hint].style.fg); for (row) |cell| try std.testing.expect(!cell.style.dim); var keys: usize = 0; diff --git a/core/views.zig b/core/views.zig index 79fff084..75e2e5d9 100644 --- a/core/views.zig +++ b/core/views.zig @@ -615,7 +615,7 @@ test "a view not live with its band open, dumped and loaded, draws before its ne 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 = 15 }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 14 }); defer p.deinit(); p.settings.jumps = .walk; var tmp = std.testing.tmpDir(.{}); @@ -631,17 +631,17 @@ test "a picker's band in a short column, dumped and loaded: its rows are the nev const low = p.view().active; p.view().active = host; p.sync(); - // Find in the pane itself (it reads): its head and its act row over - // the band, which the short column holds under what it wants. + // Find in the pane itself (it reads): its head over the band, which + // the short column holds under what it wants. p.stream.engine = .walk; pardes.Pick.open(p, host, .find, "", "", ""); p.sync(); 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.head >= 2); + try testing.expect(at.head == 1); const bytes = try dump.byteDump(p); defer gpa.free(bytes); - const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 15 }, bytes, null); + const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 14 }, bytes, null); defer q.deinit(); try testing.expectEqual(pane.view.covered, q.panes[host].?.view.covered); try testing.expectEqual(pane.tag_rows, q.panes[host].?.tag_rows); diff --git a/test/process/tty_boot.zig b/test/process/tty_boot.zig index 09311e8f..e3c09fb6 100644 --- a/test/process/tty_boot.zig +++ b/test/process/tty_boot.zig @@ -539,7 +539,7 @@ fn leader(gpa: std.mem.Allocator, exe: [:0]const u8) !void { // SPC's level, rolled in the tag once its delay is up (a frame on the // clock, which a quiet screen does not wait for) try t.key("space"); - try t.wait(5000, "↓ unroll"); + try t.wait(5000, "? help"); try t.stable(400, 5000); try t.snap("spc"); try t.key("h"); @@ -550,7 +550,7 @@ fn leader(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.stable(400, 5000); try t.snap("abandoned"); try t.key("space x"); - try t.wait(5000, "↓ unroll"); + try t.wait(5000, "? help"); try t.stable(400, 5000); try t.snap("unmapped"); // A key the level has no child for is struck and the level stays diff --git a/test/process/tty_editing.zig b/test/process/tty_editing.zig index 862897e7..093832ce 100644 --- a/test/process/tty_editing.zig +++ b/test/process/tty_editing.zig @@ -616,7 +616,7 @@ fn find(gpa: std.mem.Allocator, exe: [:0]const u8) !void { // screen does not wait for) try t.key("space"); try t.key("f"); - try t.wait(5000, "↓ unroll"); + try t.wait(5000, "? help"); try t.stable(400, 5000); try t.snap("group"); // the second f opens the query pane: every file listed, line 1 `Find ` -- cgit v1.3