diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 04:58:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 05:18:54 -0300 |
| commit | 920aaa6e6c2317aa775937b01f727fa9418b7db2 (patch) | |
| tree | 1cb02617ddfbe59712717e9ecb60ad766bf743ee /core | |
| parent | 3c4b2c99b1a969abad0a530fa99b70b2cb564af3 (diff) | |
| download | pardes-920aaa6e6c2317aa775937b01f727fa9418b7db2.tar.gz pardes-920aaa6e6c2317aa775937b01f727fa9418b7db2.zip | |
tagline, Trail, Core, layout: the tag out of rest is the owner's word, the newest step's and the head, nothing else (walk UI polish P1, UX DESIGN.md D1, the coordinator's R1-CORRECTED: the user's "why the tagline is still showing the regular tagline text?"): out of rest the path, Keep, the forward steps, the progress and the tag's own words were drawn before the head, so the key cells and the band's spines hung 40-50 columns in (shot 02's spines at column 50) and a picker's tag named the PREVIEWED file as the pane's own (shot 04: `/tmp/.../core/Store.zig ␣ f Find re 2/3`); now `‹@p1 › rank.zig:20 › ␣ ▸ b buffer…`, the head from the tag's first text column when there is no walk (`␣ f Find re`), the spines at columns 2-4; THE CHANGE: Trail.Part `.newest` writes the owner's word and the newest back step's alone, each with ` › `, a word past 24 cells cut in its middle with `…` (D1 item 4), and `stepAt(.newest)` maps a Look or Exec on any of its cells to that step; tagline.pathPrefix returns it while Trail.outOfRest (the live view's host is the pane: asking is rest and keeps its path), the old body now `restPath`; `restPrefix`, the prefix as at rest whatever the state, is what Core.sync measures `tag_lead` by (the tag's cursor and selections are offsets in its text at rest: a head over its own text moves none of them; on the shown prefix they were shifted by the path's length and back, and `| in a tag pipes the tag's own text` piped 4 wrong bytes) and what layout.wantedTagRows counts the rest rows with (a tag out of rest keeps them at least); the heads no longer lead with a space (TagState's Help/Keys/Rename/level, Pick.head, Prompt.head: the out-of-rest prefix ends in its own ` › `); no name tint, forward-step ink, unlit search word or progress out of rest (draw.zig tagTintRange, paintPaneTag; Prompt.unlit); tagline.onName and forwardSpan are off out of rest; `Trail.folded` is gone (it only told out of rest, now `.newest`: at rest it is `shown_steps`), `nameAt` takes no Pardes; TEST FIRST: Trail.zig "Enter on a word of the walk ...": out of rest `‹@pN › rank.zig:20 › ␣ ▸ ` with no older step, no directory, no Keep (on the base `‹@pN › · › rank.zig:20 › <dir>/rank.zig`: fails), a step back hides its forward step out of rest, Look maps the newest word and the owner's to their steps, and the tag at rest byte-identical after Esc; Pick.zig's reader test: the picker's head starts the tag's text (`␣ f Find pick 1/1`), no previewed path; the heads' other tests drop their leading space; test/behaviour keys.zig's prompt case reads the tag file out of rest as the head alone (`s zq`, no `/test.txt`); behaviour-test 277/277; core-test 1062/1232 (170 skipped); process-test: 8 goldens regenerated and read, each changed row the out-of-rest tag with no path (leader, pipe, msg, selregex, find, fsearch, lsp, ttyhelp: the band's spines at columns 2-4, the steps right of them, the rows no longer pushed onto a second tag row; msg's `s EXT` head and fsearch's `/` head still wrap their hints mid-word: D3's); a user meets it in every state out of rest
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
| -rw-r--r-- | core/Band.zig | 2 | ||||
| -rw-r--r-- | core/Command.zig | 18 | ||||
| -rw-r--r-- | core/Core.zig | 5 | ||||
| -rw-r--r-- | core/Pick.zig | 5 | ||||
| -rw-r--r-- | core/Prompt.zig | 22 | ||||
| -rw-r--r-- | core/TagState.zig | 38 | ||||
| -rw-r--r-- | core/Trail.zig | 93 | ||||
| -rw-r--r-- | core/bindings.zig | 10 | ||||
| -rw-r--r-- | core/draw.zig | 11 | ||||
| -rw-r--r-- | core/layout.zig | 2 | ||||
| -rw-r--r-- | core/lsp/Ask.zig | 2 | ||||
| -rw-r--r-- | core/tagline.zig | 51 |
12 files changed, 176 insertions, 83 deletions
diff --git a/core/Band.zig b/core/Band.zig index 835c249f..2fcf4a3b 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -555,7 +555,7 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push for (s.cells[@as(usize, layer.viewport.y) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme()); try std.testing.expect(std.mem.indexOf(u8, grid.items, "▶ b buffer…") != null); // The head names the level and says how to roll it up. - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, frame.allocator(), pane), " ␣ SPC ↑ roll up · ? field · esc")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, frame.allocator(), pane), "␣ SPC ↑ roll up · ? field · esc")); // Down moves the cursor; Up back to the first row, then rolls up. p.update(.{ .key = .{ .cp = Key.down } }); try std.testing.expectEqual(@as(u8, 'c'), p.view().tag_state.hi); diff --git a/core/Command.zig b/core/Command.zig index 55c336f1..334d49a2 100644 --- a/core/Command.zig +++ b/core/Command.zig @@ -685,7 +685,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 tagOf(p), " : 16 commands Tab complete · ⏎ run · C-r history · esc")); + try std.testing.expect(has(try tagOf(p), ": 16 commands Tab complete · ⏎ run · C-r history · esc")); // 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 ")); @@ -700,7 +700,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expect(has(first[7].text, "theme") and has(first[7].text, "<theme>")); // Typing filters both, by the scorer, in their order. typeKeys(p, "th"); - try std.testing.expect(has(try tagOf(p), " : th = Exec th 1 command ")); + try std.testing.expect(has(try tagOf(p), ": th = Exec th 1 command ")); try std.testing.expect(has(try bandRow(p, a, 0), "▶ theme ")); // Tab: the command, a space after it; the field's plain word is its // pardes word once it is whole. @@ -708,7 +708,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqualStrings("theme ", s.field.text()); typeKeys(p, "acme"); const worn = colors.themes[p.theme_preview.?].name; - try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, " : theme acme = Exec Theme {s} ", .{worn}))); + try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn}))); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(TagState.Kind.rest, s.kind); try std.testing.expectEqualStrings(worn, p.theme().name); @@ -718,7 +718,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, // `:sort`: the selections piped through sort, as `|sort` does. while (p.nextEffect()) |_| {} typeKeys(p, "%:sort"); - try std.testing.expect(has(try tagOf(p), " : sort = Exec Edit |sort 1 command")); + try std.testing.expect(has(try tagOf(p), ": sort = Exec Edit |sort 1 command")); p.update(.{ .key = .{ .cp = Key.enter } }); var asked: ?u32 = null; while (p.nextEffect()) |effect| if (effect == .pipe) { @@ -727,7 +727,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqualStrings("sort", p.pipe.pipeRequest(asked orelse return error.MissingPipeEffect).?.command); // `:goto 2`: Look `:2`. typeKeys(p, ":goto 2"); - try std.testing.expect(has(try tagOf(p), " : goto 2 = Look :2 <line> ")); + try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> ")); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); // S-Tab: the last row; Tab after it, round to the first. A tag word @@ -819,9 +819,9 @@ test ":theme lists the themes and the whole window wears the current one, none d try std.testing.expectEqual(Rows.values, s.prompt.command.rows); try std.testing.expectEqual(@as(u16, 2), s.nhits); try std.testing.expect(has(try bandRow(p, a, 0), "▶ on now")); - try std.testing.expect(has(try tagOf(p), " : set Wrap = Exec Wrap 2 values ")); + try std.testing.expect(has(try tagOf(p), ": set Wrap = Exec Wrap 2 values ")); typeKeys(p, "of"); - try std.testing.expect(has(try tagOf(p), " : set Wrap of = Exec Wrap of 1 value ")); + try std.testing.expect(has(try tagOf(p), ": set Wrap of = Exec Wrap of 1 value ")); p.update(.{ .key = .{ .cp = Key.tab } }); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(!p.settings.wrap); @@ -843,7 +843,7 @@ test ":theme lists the themes and the whole window wears the current one, none d // :open: the line goes to Find, the rest of it the query, the keys // after it typed into Find's field. typeKeys(p, ":o"); - try std.testing.expect(has(try tagOf(p), " : o = Exec Find ")); + try std.testing.expect(has(try tagOf(p), ": o = Exec Find ")); typeKeys(p, " te"); try std.testing.expectEqual(TagState.Kind.pick, s.kind); try std.testing.expectEqual(pardes.Pick.Source.find, pardes.Pick.live(p).?.source); @@ -885,7 +885,7 @@ test ": has a history of its own: Up and Down bring back the lines Enter ran, ne typeKeys(p, ":"); p.update(.{ .key = .{ .cp = Key.up } }); try std.testing.expectEqualStrings("goto 2", s.field.text()); - try std.testing.expect(has(try tagOf(p), " : goto 2 = Look :2 <line> ")); + try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> ")); p.update(.{ .key = .{ .cp = Key.up } }); try std.testing.expectEqualStrings("set Wrap off", s.field.text()); try std.testing.expectEqual(Rows.values, s.prompt.command.rows); diff --git a/core/Core.zig b/core/Core.zig index 2c04cc64..e43f9e83 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2010,7 +2010,10 @@ pub fn sync(p: *Pardes) void { var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room); const wa = wrap_fba.allocator(); const prefix: ?[]const u8 = tagline.prefixIn(p, wa, pane) catch null; - const lead = if (prefix) |made| made.len else pane.tag_lead; + // The tag's cursor and selections are offsets in its text at rest: + // a head shown over its own text moves none of them (UX D1). + const at_rest = if (pardes.Trail.outOfRest(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix; + const lead = if (at_rest) |made| made.len else pane.tag_lead; if (lead != pane.tag_lead) { const t = &pane.tag; const old: i32 = @intCast(pane.tag_lead); diff --git a/core/Pick.zig b/core/Pick.zig index 3bab0970..f4e26527 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -566,7 +566,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const s = &p.view().tag_state; var text: std.ArrayList(u8) = .empty; var spans: std.ArrayList(TagState.Span) = .empty; - try text.append(arena, ' '); var cells: [4][2]u32 = undefined; var ncells: usize = 0; // SPC's cell, then its keys': `␣ f`. @@ -1528,7 +1527,9 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the defer frame.deinit(); const a = frame.allocator(); const tag = try tagOf(p, a, reader); - try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null); + // Out of rest no path (UX D1): not the previewed file's, not Keep; + // the head starts the tag's text. + try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick 1/1\n")); 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); // The body previews the row's file, after a frame of its own. p.update(.tick); diff --git a/core/Prompt.zig b/core/Prompt.zig index 64e030e0..10886606 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -809,8 +809,9 @@ pub fn execWord(p: *Pardes, id: usize) void { /// The span of pane `pane`'s tag its search word takes while its places no /// longer light it (the first Esc cleared them): drawn dimmed (draw.zig). pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { + if (Trail.outOfRest(p, pane)) return null; const t = &pane.trail; - const whole = Trail.folded(p, pane); + const whole = Trail.shown_steps; for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) { if (lights(pane, &step.search) or t.cur - i > whole) return null; return t.spanOf(i, whole); @@ -1056,14 +1057,13 @@ 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 +/// 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`. pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { const s = &p.view().tag_state; const pr = &s.prompt; var text: std.ArrayList(u8) = .empty; var spans: std.ArrayList(TagState.Span) = .empty; - try text.append(arena, ' '); try styled(arena, &text, &spans, info.get(pr.op).cell, .key); try text.append(arena, ' '); const caret: u32 = @intCast(text.items.len + s.field.caret); @@ -1269,9 +1269,9 @@ 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(std.mem.endsWith(u8, try tagOf(p), " s ⏎ select · M-⏎ as a list · C-r history · esc")); + try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), "s ⏎ select · M-⏎ as a list · C-r history · esc")); typeKeys(p, "self"); - try std.testing.expect(has(try tagOf(p), " s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); + try std.testing.expect(has(try tagOf(p), "s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); 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. @@ -1310,10 +1310,10 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba typeKeys(p, "K"); p.update(.{ .key = .{ .cp = Key.up } }); try std.testing.expectEqualStrings("self..", p.view().tag_state.field.text()); - try std.testing.expect(has(try tagOf(p), " K self.. = Exec Edit g/self../ keeps 2 of 2")); + try std.testing.expect(has(try tagOf(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 tagOf(p), " K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep")); + try std.testing.expect(has(try tagOf(p), "K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep")); // 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)); @@ -1325,7 +1325,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 tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); + try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqualStrings("tr a-z A-Z", p.registers.value('|', 0).?); var asked: ?u32 = null; @@ -1362,7 +1362,7 @@ test "/ searches the body as it is typed: the current place selected, the gutter pane.body.cur_row = 2; pane.body.cur_col = 6; typeKeys(p, "/dirty"); - try std.testing.expect(has(try tagOf(p), " / dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list")); + try std.testing.expect(has(try tagOf(p), "/ dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list")); try std.testing.expectEqual(@as(?usize, 2), pane.places.current); try std.testing.expectEqualStrings("▪", try gutterAt(p, frame.allocator(), 0)); try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1)); @@ -1409,7 +1409,7 @@ 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 tagOf(p), " ? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land")); + try std.testing.expect(has(try tagOf(p), "? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land")); typeKeys(p, "x"); try std.testing.expect(has(try tagOf(p), "= Look ?dirtyx? 0 ⏎ land")); try std.testing.expectEqualDeep(was, pane.body.primaryRange(pane.file.?.content, 0)); @@ -1497,7 +1497,7 @@ 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 tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); + try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); const first = lastPipe(p) orelse return error.MissingLiveRun; const asked = p.pipe.pipeRequest(first).?; try std.testing.expectEqual(@as(usize, 2), asked.inputs.len); diff --git a/core/TagState.zig b/core/TagState.zig index 3bd79176..938a45d1 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -497,9 +497,10 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { switch (s.kind) { .rest => {}, // `Help`, its scope's keys, the field, its count: - // ` Help ␣ l hov 2/17`. + // `Help ␣ l hov 2/17` (out of rest the head starts the tag's + // text, after the owner's and the newest step's words: UX D1). .help => { - try b.put(" Help "); + try b.put("Help "); if (s.scope_root) |r| try b.keyCells(r, s.scope[0..s.scope_n]); var h = b.done(); h.caret = @intCast(b.text.items.len + s.field.caret); @@ -512,7 +513,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { // `Keys`, then the keys replayed: `Keys g ▸ d Def`; struck, // `runs nothing`. .describe => { - try b.put(" Keys "); + try b.put("Keys "); if (s.missed) { var buf: [64]u8 = undefined; const keys = if (s.scope_root) |r| bindings.chord(r, s.scope[0..s.scope_n], &buf) else bindings.keyName(s.scope[0]); @@ -540,9 +541,9 @@ 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▌ ⏎ rename · esc` (SPEC §3.5). .rename => { - try b.put(" Rename "); + try b.put("Rename "); try b.styled(Ask.renamedWord(pane) orelse "", .strike); try b.put(" → "); var h = b.done(); @@ -555,7 +556,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { }, } const cur = current(p, v) orelse return null; - try b.put(" "); try b.keyCells(cur.root, cur.path); if (!shown(p, v)) { try b.put("…"); @@ -628,7 +628,7 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing const rest = try a.dupe(u8, try testTag(p, a)); // SPC: its cell at once, the own words gone under the head. p.update(.{ .key = .{ .cp = ' ' } }); - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " ␣ …")); + try std.testing.expect(std.mem.eql(u8, try testTag(p, a), "␣ …")); // Its time is the next advance's; the level waits 250 ms from it, and // the loop wakes for it then. try std.testing.expectEqual(asked, p.view().tag_state.due_ns); @@ -638,15 +638,15 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing const woken = p.nextWake().?; try std.testing.expect(woken >= due and woken < due + pardes.frame_ns); p.clock.now_ns = due - 1; - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " ␣ …")); + try std.testing.expect(std.mem.eql(u8, try testTag(p, a), "␣ …")); p.clock.now_ns = due; const level = try testTag(p, a); - try std.testing.expect(std.mem.indexOf(u8, level, " ␣ ▸ b buffer…") != null); + try std.testing.expect(std.mem.indexOf(u8, level, "␣ ▸ b buffer…") != null); try std.testing.expect(std.mem.indexOf(u8, level, "l lsp…") != null); try std.testing.expect(std.mem.endsWith(u8, level, "↓ unroll · ? help")); // Down a level: its keys, its children. p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " ␣ l ▸ a CodeAction b Callstack") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "␣ l ▸ a CodeAction b Callstack")); // Esc: rest, the tag as it was. p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqualStrings(rest, try testTag(p, a)); @@ -662,7 +662,7 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing p.clock.now_ns = g_due - 1; try std.testing.expectEqualStrings(rest, try testTag(p, a)); p.clock.now_ns = g_due; - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " g ▸ ") != null); + try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "g ▸ ") != null); try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "d Def") != null); p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqualStrings(rest, try testTag(p, a)); @@ -750,7 +750,7 @@ test "SPC ? is Help over every root's leaves: typed in its head, filtered by the var buf: [row_max]u8 = undefined; try std.testing.expectEqualStrings("SPC t w · Wrap · view", helpLeaf(p, s.hits[0], &buf).row); const tag = try testTag(p, a); - try std.testing.expect(std.mem.indexOf(u8, tag, " Help wrap ") != null); + try std.testing.expect(std.mem.indexOf(u8, tag, "Help wrap ") != null); // Its box says it is typed in; the band holds its rows and a doc. _ = try p.render(a); const r = p.view().rects[p.view().active]; @@ -804,10 +804,10 @@ test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc for (" hk") |c| p.update(.{ .key = .{ .cp = c } }); const s = &p.view().tag_state; try std.testing.expectEqual(Kind.describe, s.kind); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys …") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys …")); for ("gd") |c| p.update(.{ .key = .{ .cp = c } }); try std.testing.expect(s.found); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys g ▸ d Def") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys g ▸ d Def")); // The level unrolled under the tag, the leaf on the cursor, its doc. try std.testing.expect(pane.band_rows >= 4); _ = try p.render(a); @@ -818,9 +818,9 @@ test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc try std.testing.expect(std.mem.indexOf(u8, text.items, "keys g d") != null); // Another sequence from the next key: ] f, then SPC l r. for ("]f") |c| p.update(.{ .key = .{ .cp = c } }); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys ] ▸ f function") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys ] ▸ f function")); for (" lr") |c| p.update(.{ .key = .{ .cp = c } }); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys ␣ l ▸ r Rename") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys ␣ l ▸ r Rename")); // Unbound: struck, runs nothing. for ("gq") |c| p.update(.{ .key = .{ .cp = c } }); try std.testing.expect(s.missed); @@ -848,14 +848,14 @@ test "C-w's level is window mode's, shown at once and kept while its keys move t const a = frame.allocator(); p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); try std.testing.expect(p.view().window_pick != null); - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " C-w …")); + try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), "C-w …")); p.advance(p.clock.now_ns); p.clock.now_ns = p.view().tag_state.due_ns; - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " C-w ▸ c Collapse d Del h Left j Down k Up l Right") != null); + try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "C-w ▸ c Collapse d Del h Left j Down k Up l Right") != null); // Sticky: a move keeps the level. p.update(.{ .key = .{ .cp = 'k' } }); try std.testing.expect(p.view().window_pick != null); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " C-w ▸ ") != null); + try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "C-w ▸ ") != null); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(p.view().window_pick == null); try std.testing.expect(p.view().tag_state.root == null); diff --git a/core/Trail.zig b/core/Trail.zig index 9223d1d3..58a72256 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -15,6 +15,7 @@ const config = @import("config.zig"); const layout = @import("layout.zig"); const panes = @import("panes.zig"); const look = @import("look.zig"); +const modal = @import("modal.zig"); const Pardes = pardes.Pardes; const Pane = panes.Pane; const Spot = look.Spot; @@ -27,7 +28,8 @@ pub const max_steps = 16; /// The bytes of a step's path or word. A jump to a longer path is no step: /// it opens a pane as `Jumps new-pane` does (look.zig open). pub const max_text = 256; -/// The newest back steps written whole; older ones fold to `·` (§6.3). +/// The newest back steps written whole at rest; older ones fold to `·` +/// (§6.3). Out of rest the owner's and the newest alone (`.newest`). pub const shown_steps = 3; /// `cur` held to the steps there are (walk.zig `.place`). @@ -311,7 +313,9 @@ pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool { // ---- the words ---- -pub const Part = enum { back, forward }; +/// `newest`: out of rest (UX D1), the owner's word and the newest back +/// step's alone, each with the separator after it. +pub const Part = enum { back, forward, newest }; /// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's /// own text; `·` when it is folded. @@ -331,19 +335,43 @@ const sep = " › "; /// The steps a part writes. fn range(t: *const Trail, part: Part) [2]usize { return switch (part) { - .back => .{ 0, t.cur }, + .back, .newest => .{ 0, t.cur }, .forward => .{ @min(t.n, t.cur + 1), t.n }, }; } +/// Whether step `i` is in what `part` writes: out of rest the owner and +/// the newest back step only. +fn writes(t: *const Trail, part: Part, i: usize) bool { + return part != .newest or t.steps[i] == .owner or i + 1 == t.cur; +} + +/// The cells of the newest step's word out of rest: a longer one is cut +/// in its middle (UX D1: `Find pick…3/6`). +const newest_cells = 24; + +/// Step `i`'s word as `part` writes it: out of rest a word longer than +/// `newest_cells` keeps its first and last cells around a `…`. +fn shownWord(t: *const Trail, part: Part, i: usize, whole: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) []const u8 { + const word = wordOf(t, i, whole, buf); + if (part != .newest or word.len <= newest_cells) return word; + const tab = 8; // a step's word holds no tab + if (panes.File.displayWidth(tab, word) <= newest_cells) return word; + const head = panes.File.byteAtDisplay(tab, word, newest_cells / 2); + var tail = word.len; + while (tail > head and panes.File.displayWidth(tab, word[tail..]) < newest_cells / 2 - 1) tail = modal.prevGrapheme(word, tail); + return std.fmt.bufPrint(cut, "{s}…{s}", .{ word[0..head], word[tail..] }) catch word; +} + /// The back steps' words, each with the separator after it (before the /// path), or the forward steps', each with one before it (after the path): /// the newest `whole` back steps whole, older ones `·` (`folded`). pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.Io.Writer.Error!void { var buf: [max_text + 16]u8 = undefined; + var cut: [max_text + 16]u8 = undefined; const r = range(t, part); - for (r[0]..r[1]) |i| switch (part) { - .back => try w.print("{s}" ++ sep, .{wordOf(t, i, whole, &buf)}), + for (r[0]..r[1]) |i| if (writes(t, part, i)) switch (part) { + .back, .newest => try w.print("{s}" ++ sep, .{shownWord(t, part, i, whole, &buf, &cut)}), .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, whole, &buf)}), }; } @@ -351,18 +379,21 @@ pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.I /// The bytes `write` writes for `part`. pub fn bytes(t: *const Trail, part: Part, whole: usize) usize { var buf: [max_text + 16]u8 = undefined; + var cut: [max_text + 16]u8 = undefined; var n: usize = 0; const r = range(t, part); - for (r[0]..r[1]) |i| n += wordOf(t, i, whole, &buf).len + sep.len; + for (r[0]..r[1]) |i| if (writes(t, part, i)) { + n += shownWord(t, part, i, whole, &buf, &cut).len + sep.len; + }; return n; } -/// The back steps pane `pane`'s tag writes whole: `shown_steps` at rest, -/// the newest alone while its tag is out of rest (SPEC §3.4.3), so a -/// state's head and the band's spines keep their room. -pub fn folded(p: *const Pardes, pane: *const Pane) usize { - const host = TagState.hostOf(p) orelse return shown_steps; - return if (p.panes[host] == pane) 1 else shown_steps; +/// Whether pane `pane`'s tag is out of rest in the live view (UX D1: its +/// path, its forward steps and its own words hidden, the owner and the +/// newest step before the head). Asking is rest. +pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool { + const host = TagState.hostOf(p) orelse return false; + return p.panes[host] == pane; } /// Where back step `i`'s word is in what `write` writes for the back @@ -378,14 +409,16 @@ pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize { /// for it, null on a separator or past them. pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 { var buf: [max_text + 16]u8 = undefined; + var cut: [max_text + 16]u8 = undefined; var x: usize = 0; const r = range(t, part); for (r[0]..r[1]) |i| { + if (!writes(t, part, i)) continue; if (part == .forward) x += sep.len; - const n = wordOf(t, i, whole, &buf).len; + const n = shownWord(t, part, i, whole, &buf, &cut).len; if (off >= x and off < x + n) return @intCast(i); x += n; - if (part == .back) x += sep.len; + if (part != .forward) x += sep.len; } return null; } @@ -841,12 +874,38 @@ test "Enter on a word of the walk, the keyboard in the tag, goes back to its ste var at: [64]u8 = undefined; const rest = try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:10 › rank.zig:20 › {s}/rank.zig Keep", .{ owner, f.dir }); try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest)); - // SPC: out of rest, the older steps are `·`, the owner and the newest - // whole; back at rest, as they were. + // SPC, its level shown: out of rest the tag is the owner, the newest + // step and the head (UX D1): no older step, no path, no Keep, none of + // its own words; back at rest, as they were. + const whole_rest = try p.gpa.dupe(u8, try tagOf(p, pane)); + defer p.gpa.free(whole_rest); p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + p.sync(); var folded_buf: [4096 + 128]u8 = undefined; - try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › · › rank.zig:20 › {s}/rank.zig", .{ owner, f.dir }))); + const out = try tagOf(p, pane); + try std.testing.expect(std.mem.startsWith(u8, out, try std.fmt.bufPrint(&folded_buf, "‹@p{d} › rank.zig:20 › ␣ ▸ ", .{owner}))); + try std.testing.expect(std.mem.indexOf(u8, out, "rank.zig:10") == null and std.mem.indexOf(u8, out, f.dir) == null and std.mem.indexOf(u8, out, "Keep") == null); + // Look on the newest step's word is that step. + try std.testing.expectEqual(@as(?u8, pane.trail.cur - 1), pardes.tagline.trailAt(p, pane, std.mem.indexOf(u8, out, "rank.zig:20").? + 3)); + try std.testing.expectEqual(@as(?u8, 0), pardes.tagline.trailAt(p, pane, 1)); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expectEqualStrings(whole_rest, try tagOf(p, pane)); + // Back a step (a forward step after the path at rest): out of rest the + // forward step is hidden as the path is. + pardes.Trail.lookStep(p, r, pane.trail.cur - 1); + p.sync(); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "rank.zig:30") != null); + p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + p.sync(); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › rank.zig:10 › ␣ ▸ ", .{owner}))); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "rank.zig:30") == null); p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + pardes.Trail.lookStep(p, r, pane.trail.cur + 1); + p.sync(); try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest)); // The keyboard in the tag, its cursor on `rank.zig:10`: Enter goes back // to that step, the keyboard in the body again. diff --git a/core/bindings.zig b/core/bindings.zig index 2df51945..43145b15 100644 --- a/core/bindings.zig +++ b/core/bindings.zig @@ -568,12 +568,12 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi p.sync(); // Its key cell at once, the level 300 ms on. p.update(.{ .key = .{ .cp = '"' } }); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), " \" …")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), "\" …")); p.advance(p.clock.now_ns); try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns); p.clock.now_ns = p.view().tag_state.due_ns; const rolled = try tagline.tagText(p, a, pane); - try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null); + try std.testing.expect(std.mem.indexOf(u8, rolled, "\" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null); try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null); // Down unrolls: a row each, the cursor on the default, its value // beside them. @@ -596,13 +596,13 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi try std.testing.expect(std.mem.indexOf(u8, band.items, "return best;") != null); // Enter chooses it: its verbs, rolled. p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after P before R replace y into") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" a ▸ p after P before R replace y into") != null); try std.testing.expect(!p.view().tag_state.unrolled); // Backspace: the registers again; a register's own key goes down too. p.update(.{ .key = .{ .cp = Key.backspace } }); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" ▸ \" self.dirty") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" ▸ \" self.dirty") != null); p.update(.{ .key = .{ .cp = 'a' } }); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" a ▸ p after") != null); // p pastes it after the selection, and the tag is at rest. p.update(.{ .key = .{ .cp = 'p' } }); try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "const best = rank(q, name) orelse continue;") != null); diff --git a/core/draw.zig b/core/draw.zig index 68778667..179b7cfc 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -690,6 +690,8 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u } fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } { + // Out of rest no name is shown (UX D1). + if (pardes.Trail.outOfRest(p, pane)) return null; if (pane.isTerminal()) { // `tag` is the first row; a prefix longer than it ran to a second. var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n"); @@ -700,7 +702,7 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len } return null; } - var start: usize = tagline.nameAt(p, pane); + var start: usize = tagline.nameAt(pane); const name = if (pane.file) |file| if (pane.prompt == .name) pane.input.own orelse file.path else file.path else if (pane.addon) |k| blk: { @@ -1013,7 +1015,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, else if (pane.prompt == .name) caret: { // A drafted name is the prefix: its caret is on row 0 of the tag, // the rows it wrapped onto included. - const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); + const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); if (at.row < top or at.row >= top + rows) break :caret null; break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) }; } else if (pane.focus == .tag and pane.prompt == .none and head == null) caret: { @@ -1031,8 +1033,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); } // The pane's progress at its first row's right end, where the row has - // room for it (SPEC §10.2). - if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| { + // room for it (SPEC §10.2); out of rest the head's right block is + // there (UX D1). + if (top == 0 and rows > 0 and !pardes.Trail.outOfRest(p, pane)) for (p.messages.live[0..p.messages.live_len]) |*said| { if (said.kind != .progress or said.pane != pane.serial) continue; var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; diff --git a/core/layout.zig b/core/layout.zig index c0d21d6d..0a773cab 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -594,7 +594,7 @@ pub fn wantedTagRows(p: *Pardes, id: usize) u16 { var wrap_room: [32 * 1024]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 prefix = tagline.restPrefix(p, wa, pane) catch return pane.tag_rows; const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) 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))); diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index bb1eccb6..6e6f87e5 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -761,7 +761,7 @@ test "SPC l r types the new name in the pane's own tag, the body showing each pl var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), " Rename best → bester") != null); + try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), "Rename best → bester") != null); p.sync(); const sf = try p.render(a); const body = sf.region(.body, id).?.rect; diff --git a/core/tagline.zig b/core/tagline.zig index e95d68de..3256f824 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -124,6 +124,22 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { /// PDF's page, a terminal's directory -- without the space that parts it /// from the tag's own text. It is never stored, and never edited. pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { + // Out of rest (UX D1) the owner's word and the newest step's, each with + // its ` › `, before the head: the path, the forward steps and Keep + // hidden until rest (a picker's preview is no name of the pane's). + if (pardes.Trail.outOfRest(p, pane)) { + if (pane.trail.n == 0) return ""; + const room = try arena.alloc(u8, pane.trail.bytes(.newest, 1)); + var w: std.Io.Writer = .fixed(room); + pane.trail.write(.newest, 1, &w) catch return error.OutOfMemory; + return w.buffered(); + } + return restPath(p, arena, pane); +} + +/// The computed start of a pane's tag at rest, whatever its state: what +/// the tag's own text follows. +fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { // What is drawn: with no graphics, glyph art whatever `Petscii` says. if (pane.addon != null) return pardes.Kind.prefix(p, arena, pane); // A command pane: its directory, the line it runs, and how that went. @@ -163,7 +179,7 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co // Its walk's back steps before the name, its forward steps after // it (Trail.zig), in the room `bytes` measures them. const keep_word = if (keep) " Keep" else ""; - const whole = pardes.Trail.folded(p, pane); + const whole = pardes.Trail.shown_steps; const room = try arena.alloc(u8, pane.trail.bytes(.back, whole) + name.len + pane.trail.bytes(.forward, whole) + keep_word.len); var w: std.Io.Writer = .fixed(room); pane.trail.write(.back, whole, &w) catch return error.OutOfMemory; @@ -184,15 +200,15 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co } /// Where a file's name starts in its tag: after its walk's back steps. -pub fn nameAt(p: *const Pardes, pane: *const Pane) usize { - return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.folded(p, pane)) else 0; +pub fn nameAt(pane: *const Pane) usize { + return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.shown_steps) else 0; } /// The bytes of a file's tag its walk's forward steps take, after its name. pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { const f = pane.file orelse return .{ 0, 0 }; - if (pane.trail.n == 0) return .{ 0, 0 }; - const whole = pardes.Trail.folded(p, pane); + if (pane.trail.n == 0 or pardes.Trail.outOfRest(p, pane)) return .{ 0, 0 }; + const whole = pardes.Trail.shown_steps; const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; const lo = pane.trail.bytes(.back, whole) + name.len; return .{ lo, lo + pane.trail.bytes(.forward, whole) }; @@ -202,9 +218,10 @@ pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { /// text, if one is there. pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 { if (pane.trail.n == 0 or pane.file == null) return null; - const whole = pardes.Trail.folded(p, pane); + if (pardes.Trail.outOfRest(p, pane)) return pane.trail.stepAt(.newest, 1, at); + const whole = pardes.Trail.shown_steps; const ahead = forwardSpan(p, pane); - if (at < nameAt(p, pane)) return pane.trail.stepAt(.back, whole, at); + if (at < nameAt(pane)) return pane.trail.stepAt(.back, whole, at); if (at >= ahead[0] and at < ahead[1]) return pane.trail.stepAt(.forward, whole, at - ahead[0]); return null; } @@ -227,7 +244,17 @@ pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 { /// The prefix as the tag shows it, built in `arena`. pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { - const prefix = try pathPrefix(p, arena, pane); + // Out of rest the head follows: its words end in their own space. + if (pardes.Trail.outOfRest(p, pane)) return arena.dupe(u8, try pathPrefix(p, arena, pane)); + return restPrefix(p, arena, pane); +} + +/// The prefix as the tag has it at rest, whatever its state: what its own +/// text follows, so what its cursor and selections are offsets after +/// (Core.sync's `tag_lead`), and the rows it takes at rest +/// (layout.wantedTagRows). +pub fn restPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { + const prefix = try restPath(p, arena, pane); // The space between the prefix and the tag's own text is the text's // (every default starts with one), but the prefix is computed, so it // cannot trust the text to keep it: with it deleted, Look and Exec @@ -411,13 +438,13 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso /// words; null off it. pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize { const tab = p.settings.tab; - if (row + pane.tag_top != 0) return null; + if (row + pane.tag_top != 0 or pardes.Trail.outOfRest(p, pane)) return null; const f = pane.file orelse return null; if (!panes.Output.fileTraits(f.output).saves) return null; const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; var w: std.Io.Writer = .fixed(&room); - pane.trail.write(.back, pardes.Trail.folded(p, pane), &w) catch return null; + pane.trail.write(.back, pardes.Trail.shown_steps, &w) catch return null; const lead = panes.File.displayWidth(tab, w.buffered()); if (col < lead or col >= lead + panes.File.displayWidth(tab, name)) return null; return col - lead; @@ -432,8 +459,8 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { if (!panes.Output.fileTraits(f.output).saves or pane.tag.cur_row != 0) return false; // The name starts after its walk's words. const col: usize = @intCast(@max(0, pane.tag.cur_col)); - if (col < nameAt(p, pane)) return false; - const at = col - nameAt(p, pane); + if (col < nameAt(pane)) return false; + const at = col - nameAt(pane); const back = key.cp == pardes.Key.backspace or pardes.hit(key, config.insert_backspace_alias); const forward = key.cp == pardes.Key.delete or pardes.hit(key, config.insert_delete_alias); const typed = key.text.len > 0 and !key.ctrl and !key.alt; |
