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/layout.zig | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'core/layout.zig') diff --git a/core/layout.zig b/core/layout.zig index c8fb91f9..ae15c6e9 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -592,7 +592,7 @@ pub const min_body_rows = 2; /// wants a row more. pub fn wantedTagRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return BOX_H; - return tagRows(p, id, tagline.computedWords(pane)); + return tagRows(p, id, tagline.tagWords(p, pane)); } /// The rows pane `id`'s tag at rest takes with computed words `words`. @@ -609,20 +609,19 @@ fn tagRows(p: *Pardes, id: usize, words: []const u8) u16 { return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); } -/// The rows pane `id`'s tag's text takes now: out of rest its head -/// (TagState) after what of its prefix stays (UX D1), wrapped at its width -/// as Pardes.sync wraps it; at rest what wantedTagRows says. +/// The rows pane `id`'s head takes under its tag out of rest (TagState, +/// UX DESIGN M2), wrapped at the tag's width as the band draws it; none at +/// rest. pub fn headRows(p: *Pardes, id: usize) u16 { - const pane = p.panes[id] orelse return BOX_H; - if (pane.collapsed or !pane.tag_expanded) return BOX_H; + const pane = p.panes[id] orelse return 0; + if (pane.collapsed) return 0; var wrap_room: [Pane.prefix_room]u8 = undefined; var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room); const wa = wrap_fba.allocator(); - const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows; - const tail = tagline.shownTail(p, wa, pane) catch return pane.tag_rows; - const whole = std.mem.concat(wa, u8, &.{ prefix, tail }) catch return pane.tag_rows; - const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows; - return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); + // A head with no room to be made in is a row still. + const head = (pardes.TagState.head(p, wa, pane) catch return 1) orelse return 0; + const shown = tagline.wrapTag(p.settings.tab, wa, head.text, tagline.tagWidth(p, id)) catch return 1; + return @intCast(@min(shown.rows(), MAX_TAG_ROWS)); } /// The rows a placement, and a `size`, leave a pane: its tag at its width @@ -1608,22 +1607,22 @@ pub fn compute(p: *Pardes) void { /// The fewest rows a pane is laid out with: a terminal keeps its tag and /// `min_body_rows` (a shorter one loses its prompt and reads busy for /// ever), a text pane may shrink to its tag, as acme's windows do. A tag -/// out of rest has the rows for its head and its band, drawn over its body -/// (UX DESIGN I1); a picker's (code actions' too: its body is the preview) -/// a body of 60 % of the pane and 6 rows at least under them (UX D6). Those -/// are borrowed from the column's other panes, which shrink to their tags -/// until it rolls up (walk UI SPEC §3.6). A terminal's and a kind's size -/// is their user's: a transient state never resizes the pty under a -/// program or a kind's view (a PDF's), it is drawn over as much of them as -/// it has (R3). +/// 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). fn floorRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return 0; - const band = if (pane.isTerminal() or pane.addon != null) 0 else pardes.Band.takes(p, id); - if (band > 0) { + const under = if (pane.isTerminal() or pane.addon != null) 0 else headRows(p, id) + pardes.Band.takes(p, id); + if (under > 0) { // Worked out from the state, never the last sync's rows (the first // layout after a head changed read the rows of the one before, and // the next moved the body). - const above = @max(wantedTagRows(p, id), headRows(p, id) + band); + const above = wantedTagRows(p, id) + under; if (p.view().tag_state.kind != .pick) return above; // A body of 60 % is one and a half times what is above it. return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2); -- 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/layout.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