diff options
| -rw-r--r-- | core/Prompt.zig | 4 | ||||
| -rw-r--r-- | core/Trail.zig | 192 | ||||
| -rw-r--r-- | core/draw.zig | 35 | ||||
| -rw-r--r-- | core/tagline.zig | 53 | ||||
| -rw-r--r-- | test/snapshots/fsearch.golden | 8 | ||||
| -rw-r--r-- | test/snapshots/lookrange.golden | 4 |
6 files changed, 236 insertions, 60 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig index 27b59649..c3d9959a 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -811,9 +811,9 @@ pub fn execWord(p: *Pardes, id: usize) void { pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { if (Trail.outOfRest(p, pane)) return null; const t = &pane.trail; - const whole = Trail.shown_steps; + const whole = pardes.tagline.folded(p, pane); for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) { - if (lights(pane, &step.search) or t.cur - i > whole) return null; + if (lights(pane, &step.search) or t.isFolded(i, whole)) return null; return t.spanOf(i, whole); }; return null; diff --git a/core/Trail.zig b/core/Trail.zig index 58a72256..e22a58b6 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -318,18 +318,36 @@ pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool { 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. -fn wordOf(t: *const Trail, i: usize, whole: usize, buf: *[max_text + 16]u8) []const u8 { - const s = &t.steps[i]; - if (s.* != .owner and i < t.cur and t.cur - i > whole) return "·"; +/// own text. A place's file is named by its basename, or where another +/// step's file has the same one, by the shortest end of its path the other +/// does not share (UX D8: `core/x.zig:3` beside `dev/x.zig:9`). +fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 { // The step itself, not a copy: a word's text is the step's own bytes. - return switch (s.*) { + return switch (t.steps[i]) { .owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits - .place => |at| std.fmt.bufPrint(buf, "{s}:{d}", .{ std.Io.Dir.path.basename(at.path.slice()), at.line }) catch unreachable, // a basename and a u32 fit + .place => |*at| place: { + const path = at.path.slice(); + var from = if (std.mem.lastIndexOfScalar(u8, path, '/')) |slash| slash + 1 else 0; + while (from > 0 and shared(t, i, path[from..])) from = if (std.mem.lastIndexOfScalar(u8, path[0 .. from - 1], '/')) |slash| slash + 1 else 0; + break :place std.fmt.bufPrint(buf, "{s}:{d}", .{ path[from..], at.line }) catch unreachable; // a path and a u32 fit + }, .list, .search, .recipe => |*w| w.text.slice(), }; } +/// Whether another step's file, not step `i`'s, has a path ending in `end` +/// at a `/`. +fn shared(t: *const Trail, i: usize, end: []const u8) bool { + const own = t.steps[i].place.path.slice(); + for (t.steps[0..t.n], 0..) |*s, j| { + if (j == i or s.* != .place) continue; + const path = s.place.path.slice(); + if (std.mem.eql(u8, path, own) or !std.mem.endsWith(u8, path, end)) continue; + if (path.len == end.len or path[path.len - end.len - 1] == '/') return true; + } + return false; +} + const sep = " › "; /// The steps a part writes. @@ -340,20 +358,36 @@ fn range(t: *const Trail, part: Part) [2]usize { }; } -/// 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 forward steps written whole after the path at rest; the rest fold. +pub const shown_ahead = 2; + +/// Steps [lo, hi) of `part` folded into one dim `+N` word where the first +/// of them is (UX D8): at rest the back steps older than the newest +/// `whole` (never the owner), the forward steps past `shown_ahead`. +fn foldOf(t: *const Trail, part: Part, whole: usize) [2]usize { + return switch (part) { + .back => back: { + const lo: usize = @intFromBool(t.cur > 0 and t.steps[0] == .owner); + break :back .{ lo, @max(lo, t.cur -| whole) }; + }, + .forward => .{ @min(t.n, t.cur + 1 + shown_ahead), t.n }, + .newest => .{ 0, 0 }, + }; } /// 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); +/// Step `i`'s word as `part` writes it, null where it writes none: a +/// folded step's is the fold's `+N` on its first, none on the others; out +/// of rest the owner's and the newest step's alone, a word longer than +/// `newest_cells` keeping its first and last cells around a `…`. +fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) ?[]const u8 { + if (part == .newest and t.steps[i] != .owner and i + 1 != t.cur) return null; + const fold = foldOf(t, part, whole); + if (i >= fold[0] and i < fold[1]) return if (i == fold[0]) std.fmt.bufPrint(buf, "+{d}", .{fold[1] - fold[0]}) catch unreachable else null; + const word = wordOf(t, i, 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; @@ -364,15 +398,16 @@ fn shownWord(t: *const Trail, part: Part, i: usize, whole: usize, buf: *[max_tex } /// 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`). +/// path), or the forward steps', each with one before it (after the path), +/// the folded ones as one `+N` (`foldOf`); out of rest (`newest`) the +/// owner's and the newest's. 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| 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)}), + for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf, &cut)) |word| switch (part) { + .back, .newest => try w.print("{s}" ++ sep, .{word}), + .forward => try w.print(sep ++ "{s}", .{word}), }; } @@ -382,12 +417,23 @@ pub fn bytes(t: *const Trail, part: Part, whole: usize) usize { var cut: [max_text + 16]u8 = undefined; var n: usize = 0; const r = range(t, part); - for (r[0]..r[1]) |i| if (writes(t, part, i)) { - n += shownWord(t, part, i, whole, &buf, &cut).len + sep.len; + for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf, &cut)) |word| { + n += word.len + sep.len; }; return n; } +/// The back step `n` and N walk (Pick.walkList, Prompt): the newest list +/// or search; its word is underlined (UX D8). +pub fn walked(t: *const Trail) ?u8 { + var i: usize = t.cur; + while (i > 0) { + i -= 1; + if (t.steps[i] == .list or t.steps[i] == .search) return @intCast(i); + } + return null; +} + /// 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. @@ -396,13 +442,26 @@ pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool { return p.panes[host] == pane; } -/// Where back step `i`'s word is in what `write` writes for the back -/// steps, the newest `whole` whole. +/// Where back step `i`'s word (the fold's `+N` for a folded one) is in +/// what `write` writes for the back steps, the newest `whole` whole. pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize { var buf: [max_text + 16]u8 = undefined; + var cut: [max_text + 16]u8 = undefined; var x: usize = 0; - for (0..i) |j| x += wordOf(t, j, whole, &buf).len + sep.len; - return .{ x, x + wordOf(t, i, whole, &buf).len }; + for (0..i) |j| if (wordIn(t, .back, whole, j, &buf, &cut)) |word| { + x += word.len + sep.len; + }; + const fold = foldOf(t, .back, whole); + const at = if (i >= fold[0] and i < fold[1]) fold[0] else i; + if (at < i) return spanOf(t, at, whole); + const word: []const u8 = wordIn(t, .back, whole, i, &buf, &cut) orelse ""; + return .{ x, x + word.len }; +} + +/// Whether back step `i` is in the fold's `+N`. +pub fn isFolded(t: *const Trail, i: usize, whole: usize) bool { + const fold = foldOf(t, .back, whole); + return i >= fold[0] and i < fold[1]; } /// The step whose word in `part` is at byte `off` of what `write` wrote @@ -412,12 +471,13 @@ pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 { var cut: [max_text + 16]u8 = undefined; var x: usize = 0; const r = range(t, part); + const fold = foldOf(t, part, whole); for (r[0]..r[1]) |i| { - if (!writes(t, part, i)) continue; + const word = wordIn(t, part, whole, i, &buf, &cut) orelse continue; if (part == .forward) x += sep.len; - const n = shownWord(t, part, i, whole, &buf, &cut).len; - if (off >= x and off < x + n) return @intCast(i); - x += n; + // A fold's `+N` is the step nearest the path of those it holds. + if (off >= x and off < x + word.len) return @intCast(if (i == fold[0] and fold[0] < fold[1]) (if (part == .back) fold[1] - 1 else fold[0]) else i); + x += word.len; if (part != .forward) x += sep.len; } return null; @@ -761,19 +821,85 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, p.panes[rd].?), "› Refs 2/2 ›") != null); } -test "a trail keeps its newest three back steps whole, older ones fold to ·, and a click on a · goes back to its step" { +test "a trail keeps its newest three back steps whole, older ones fold into one dim `+N` after the owner, and a click on it goes back to the newest of them; forward steps past two fold the same way" { var f: Fixture = .{ .p = undefined, .tmp = undefined }; try f.init(60); defer f.deinit(); const p = f.p; const owner = p.panes[f.held].?.serial; - for ([_]usize{ 10, 20, 30, 40, 50 }) |line| f.look(f.held, "rank.zig", line); + for ([_]usize{ 10, 20, 30, 40, 50, 60 }) |line| f.look(f.held, "rank.zig", line); const r = p.view().active; + const pane = p.panes[r].?; + // Wide enough for the three newest whole on its one row. + p.update(.{ .resize = .{ .cols = 400, .rows = 60 } }); var buf: [4096 + 128]u8 = undefined; var at: [64]u8 = undefined; - try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "‹@p{d} › · › rank.zig:20 › rank.zig:30 › rank.zig:40 › {s}/rank.zig Keep ", .{ owner, f.dir }))); - try clickTag(p, r, "·", .right); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&buf, "‹@p{d} › +2 › rank.zig:30 › rank.zig:40 › rank.zig:50 › {s}/rank.zig Keep ", .{ owner, f.dir }))); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const fold = try tagCell(p, r, "+2"); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().lineno }, s.at(fold[0], fold[1]).style.fg); + try clickTag(p, r, "+2", .right); + try std.testing.expectEqualStrings("rank.zig:20", f.at(&at)); + // Back at the first: five forward steps, the two nearest whole. + try clickTag(p, r, "rank.zig:10", .right); try std.testing.expectEqualStrings("rank.zig:10", f.at(&at)); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), try std.fmt.bufPrint(&buf, "{s}/rank.zig › rank.zig:20 › rank.zig:30 › +3 Keep ", .{f.dir})) != null); +} + +test "the walk never adds a row to a tag at rest: its steps fold further, down to the newest alone, where they would" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + f.look(f.held, "rank.zig", 10); + for ([_]usize{ 20, 30, 40, 50, 60, 70 }) |line| { + f.look(p.view().active, "place.zig", line); + f.look(p.view().active, "rank.zig", line); + } + const r = p.view().active; + const pane = p.panes[r].?; + try std.testing.expect(pane.trail.cur > 4); + // A width 35 cells past what the tag takes with no walk: room on its + // row for the owner, a fold and the newest, not for three. + const walk = pane.trail; + pane.trail.n = 0; + pane.trail.cur = 0; + const bare = panes.File.displayWidth(p.settings.tab, try tagOf(p, pane)); + pane.trail = walk; + const extra = p.view().screen_w - pardes.tagline.tagWidth(p, r); + p.update(.{ .resize = .{ .cols = @intCast(bare + 35 + extra), .rows = 60 } }); + p.sync(); + try std.testing.expectEqual(@as(u16, 1), pardes.layout.wantedTagRows(p, r)); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), " › +") != null); +} + +test "two steps whose files have the same name are told apart by the shortest path they do not share; the word n walks is underlined" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + try f.tmp.dir.createDirPath(std.testing.io, "core"); + try f.tmp.dir.writeFile(std.testing.io, .{ .sub_path = "core/rank.zig", .data = "a\nb\nc\n" }); + f.look(f.held, "rank.zig", 12); + f.look(p.view().active, "core/rank.zig", 2); + f.look(p.view().active, "place.zig", 3); + const r = p.view().active; + var buf: [4096 + 128]u8 = undefined; + const tag = try tagOf(p, p.panes[r].?); + try std.testing.expect(std.mem.indexOf(u8, tag, try std.fmt.bufPrint(&buf, " › {s}/rank.zig:12 › core/rank.zig:2 › ", .{std.Io.Dir.path.basename(f.dir)})) != null); + // A list word: the one n walks, underlined. + p.panes[r].?.trail.steps[1] = .{ .list = .{} }; + p.panes[r].?.trail.steps[1].list.text.set("Find x 1/2"); + p.sync(); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const word = try tagCell(p, r, "Find x 1/2"); + try std.testing.expect(s.at(word[0], word[1]).style.ul == .single); + const other = try tagCell(p, r, "place.zig"); + try std.testing.expect(s.at(other[0], other[1]).style.ul != .single); } test "Ctrl-o goes back one place in a reader's walk and Ctrl-i forward again; past its first place, or from a held pane, the jump list's" { diff --git a/core/draw.zig b/core/draw.zig index be4230c4..28b9f22d 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -695,7 +695,7 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len } return null; } - var start: usize = tagline.nameAt(pane); + var start: usize = tagline.nameAt(p, 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: { @@ -945,7 +945,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R /// Bytes `lo` to `hi` of a tag's text in `ink`, over whichever of its /// shown rows (`lines`, from shown row `top`, drawn at `x`, `y`, `w` /// wide) they wrapped onto. -fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const u8, top: usize, x: u16, y: u16, w: u16, lo: usize, hi: usize, ink: [3]u8) void { +fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const u8, top: usize, x: u16, y: u16, w: u16, lo: usize, hi: usize, ink: [3]u8, under: bool) void { const a = modal.positionAt(shown.text, shown.fromReal(lo)); const b = modal.positionAt(shown.text, shown.fromReal(hi)); var row = @max(a.row, top); @@ -956,8 +956,11 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const var col = panes.File.rawDisplayCol(p.settings.tab, line, @min(from, line.len)); const end = panes.File.rawDisplayCol(p.settings.tab, line, @min(to, line.len)); const row_y = y + @as(u16, @intCast(row - top)); - while (col < end and col < w) : (col += 1) - s.at(x + @as(u16, @intCast(col)), row_y).style.fg = .{ .rgb = ink }; + while (col < end and col < w) : (col += 1) { + const style = &s.at(x + @as(u16, @intCast(col)), row_y).style; + style.fg = .{ .rgb = ink }; + if (under) style.ul = .single; + } } } @@ -1014,7 +1017,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(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); + const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, 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: { @@ -1059,12 +1062,26 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, // wrapped onto. const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len]; if (tagTintRange(p, pane, first_line, prefix_len)) |name| if (name.lo < name.hi) - inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg); - // A walk's forward steps, after the name, dimmed (Trail.zig). + inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg, false); + // A walk's forward steps, after the name, dimmed (Trail.zig); its fold + // `+N` too; the word n walks underlined in the key ink (UX D8). const ahead = tagline.forwardSpan(p, pane); - if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno); + if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno, false); + if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) { + const kept = tagline.folded(p, pane); + const t = &pane.trail; + const first: usize = @intFromBool(t.steps[0] == .owner); + if (t.isFolded(first, kept)) { + const fold = t.spanOf(first, kept); + inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), chrome.lineno, false); + } + if (t.walked()) |i| if (!t.isFolded(i, kept)) { + const word = t.spanOf(i, kept); + inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, word[0], @min(word[1], first_line.len), chrome.box, true); // P2: the key role + }; + } // A search word its places no longer light, dimmed (Prompt.zig). - if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno); + if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno, false); // The head's keys in the key ink, its dimmed, underlined and struck // words (TagState.Span), over whichever rows they wrapped onto. if (head) |h| for (h.spans) |span| { diff --git a/core/tagline.zig b/core/tagline.zig index 3256f824..5f7222e6 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -179,7 +179,7 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 // 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.shown_steps; + const whole = folded(p, pane); 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; @@ -200,15 +200,48 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 } /// Where a file's name starts in its tag: after its walk's back steps. -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; +pub fn nameAt(p: *const Pardes, pane: *const Pane) usize { + return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, folded(p, pane)) else 0; +} + +/// The back steps a file's tag writes whole at rest (UX D8): the newest +/// three (Trail.shown_steps), fewer, down to the newest alone, while its +/// walk would make the tag take more rows than it takes with none: the +/// walk never adds a row to a tag at rest (as far as the newest alone +/// lets it). +pub fn folded(p: *const Pardes, pane: *const Pane) usize { + const t = &pane.trail; + const f = pane.file orelse return pardes.Trail.shown_steps; + if (t.n == 0) return pardes.Trail.shown_steps; + const id = panes.paneIdOf(p, pane) orelse return pardes.Trail.shown_steps; + const tab = p.settings.tab; + const width = tagWidth(p, id); + const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; + const bare = panes.File.displayWidth(tab, name) + @as(usize, if (pardes.Trail.reading(p, pane)) " Keep".len else 0) + panes.File.displayWidth(tab, curTail(pane)); + var whole: usize = pardes.Trail.shown_steps; + while (whole > 1 and rowsOf(bare + walkCells(t, whole, tab), width) > rowsOf(bare, width)) whole -= 1; + return whole; +} + +/// The cells a walk's words take at rest with its newest `whole` back +/// steps whole. +fn walkCells(t: *const pardes.Trail, whole: usize, tab: u16) usize { + var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; + var w: std.Io.Writer = .fixed(&room); + t.write(.back, whole, &w) catch {}; + t.write(.forward, whole, &w) catch {}; + return panes.File.displayWidth(tab, w.buffered()); +} + +fn rowsOf(cells: usize, width: usize) usize { + return @max(1, (cells + width - 1) / width); } /// 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 or pardes.Trail.outOfRest(p, pane)) return .{ 0, 0 }; - const whole = pardes.Trail.shown_steps; + const whole = folded(p, pane); 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) }; @@ -219,9 +252,9 @@ pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 { if (pane.trail.n == 0 or pane.file == null) return null; if (pardes.Trail.outOfRest(p, pane)) return pane.trail.stepAt(.newest, 1, at); - const whole = pardes.Trail.shown_steps; + const whole = folded(p, pane); const ahead = forwardSpan(p, pane); - if (at < nameAt(pane)) return pane.trail.stepAt(.back, whole, at); + if (at < nameAt(p, 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; } @@ -268,7 +301,7 @@ pub fn restPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 /// The tag's own text: what the user made of it, or until then the /// default a pane of its kind starts with. -pub fn curTail(pane: *Pane) []const u8 { +pub fn curTail(pane: *const Pane) []const u8 { return pane.tag.own orelse defaultTail(pane); } @@ -444,7 +477,7 @@ pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize { 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.shown_steps, &w) catch return null; + pane.trail.write(.back, folded(p, pane), &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; @@ -459,8 +492,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(pane)) return false; - const at = col - nameAt(pane); + if (col < nameAt(p, pane)) return false; + const at = col - nameAt(p, 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; diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 59037755..627fb21c 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -97,8 +97,8 @@ |28: 8 l8 |29: 9 l9 == snap landed grid=180x31 cursor=97,22 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse -|17: ls Follow Del +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll +|17: ls ow Del |18: g.txt 2 MARK a |19: 3 l3 |20: 4 l4 @@ -112,7 +112,7 @@ |28: 12 l12 |29: == snap n grid=180x31 cursor=97,27 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 3/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 3/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll |18: g.txt 1 l1 |19: 2 MARK a |20: 3 l3 @@ -126,7 +126,7 @@ |28: 11 l11 |29: 12 l12 == snap N grid=180x31 cursor=97,23 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll == snap cancel grid=180x31 cursor=97,23 == snap nomatch grid=180x31 cursor=118,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › /MARK/ 2/3 › / zzqq = Look /zzqq/ 0 ⏎ land · M-⏎ as a list · C-r history · esc diff --git a/test/snapshots/lookrange.golden b/test/snapshots/lookrange.golden index a0cbd3be..1ea85a6e 100644 --- a/test/snapshots/lookrange.golden +++ b/test/snapshots/lookrange.golden @@ -100,7 +100,7 @@ |7: /NEEDLE/ 2/2 › /tmp/pardes-snap/lookrange/cwd/r.txt Save Term Collapse Follow Del |30: /tmp/pardes-snap/lookrange/cwd/r.txt:8 == style hit1 grid=150x31 -|7: 0-1 d,#add38a, 2-47 #becfc4,#314738, 48-53 #dfbce5,#314738, 54-149 #becfc4,#314738, +|7: 0-1 d,#add38a, 2-13 #add38a,#314738,u 14-14 #add38a,#314738, 15-47 #becfc4,#314738, 48-53 #dfbce5,#314738, 54-149 #becfc4,#314738, |14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #e5eee5,#352e19, 16-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #e5eee5,#0d1410, 12-17 #f5f7ee,#3c614a, 18-149 #f5f7ee,#0d1410, |16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, @@ -110,7 +110,7 @@ |7: /NEEDLE/ 1/2 ↻ › /tmp/pardes-snap/lookrange/cwd/r.txt Save Term Collapse Follow Del |30: · /tmp/pardes-snap/lookrange/cwd/r.txt /NEEDLE/ 1/2 ↻ · line 7 1 message · SPC h m == style hit2 grid=150x31 -|7: 0-1 d,#add38a, 2-49 #becfc4,#314738, 50-55 #dfbce5,#314738, 56-149 #becfc4,#314738, +|7: 0-1 d,#add38a, 2-15 #add38a,#314738,u 16-16 #add38a,#314738, 17-49 #becfc4,#314738, 50-55 #dfbce5,#314738, 56-149 #becfc4,#314738, |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-9 #e5eee5,#0d1410, 10-15 #f5f7ee,#3c614a, 16-16 #f5f7ee,#0d1410, 17-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-17 #e5eee5,#352e19, 18-149 #e5eee5,#0d1410, |22: 0-0 d,#e5eee5, 1-149 d,#0d1410, |
