diff options
| -rw-r--r-- | core/Pick.zig | 61 | ||||
| -rw-r--r-- | test/snapshots/fsearch.golden | 8 | ||||
| -rw-r--r-- | test/snapshots/lsp.golden | 4 |
3 files changed, 67 insertions, 6 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index c5b639cd..8239be6a 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -715,6 +715,30 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const r = try rowAt(p, pk, arena, i); row.* = .{ .text = r.text, .key = r.key, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i), .meta = r.meta }; } + // A place's text (a Grep's line, a list's): its `path:line` in the dim + // ink and the text after it in one column, the widest place shown + // before it (UX E7 2b: the old +Search's column). Bounded by the rows + // shown. + if (pk.source == .grep or pk.source == .all or pk.source == .list) { + var widest: usize = 0; + for (rows) |row| if (row.pre > 0 and row.pre < row.text.len) { + widest = @max(widest, File.displayWidth(p.settings.tab, row.text[0 .. std.mem.indexOfScalarPos(u8, row.text, row.pre, ' ') orelse row.text.len])); + }; + for (rows) |*row| if (row.pre > 0 and row.pre < row.text.len) { + // The place up to its blank: a column (`:3:1`) and the `:` a + // compiler's `path:line:col: words` puts after it are its. + const end = std.mem.indexOfScalarPos(u8, row.text, row.pre, ' ') orelse row.text.len; + row.quiet = .{ 0, @intCast(end) }; + const pad = widest - File.displayWidth(p.settings.tab, row.text[0..end]); + if (pad == 0) continue; + const blanks = try arena.alloc(u8, pad); + @memset(blanks, ' '); + row.text = try std.mem.concat(arena, u8, &.{ row.text[0..end], blanks, row.text[end..] }); + const marks = try arena.alloc(u16, row.marks.len); + for (marks, row.marks) |*m, at| m.* = if (at >= end) at + @as(u16, @intCast(pad)) else at; + row.marks = marks; + }; + } out[0] = .{ .rows = rows }; return out; } @@ -2395,3 +2419,40 @@ test "a picker's preview is legible as one (UX D7): its landing line on the hit p.update(.{ .key = .{ .cp = pardes.Key.escape } }); try std.testing.expect(!pardes.Messages.noticeRow(p, 120, &buf).quiet_left); } + +test "a list of places (a Grep's, a list's) shows each row's `path:line` in the dim ink and its text after it in one column, the widest place shown before it (UX E7 2b)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "a.zig", "one\ntwo\nconst x = 1;\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "a_longer_name.zig", "fn y() void {}\n"); + defer p.gpa.free(b_path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:3:1 const x = 1;\n{s}:1:4 fn y() void {{}}\n", .{ a_path, b_path }); + defer std.testing.allocator.free(rows); + open(p, asker, .list, "Refs", "", rows); + p.update(.tick); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const got = (try steps(p, frame.allocator()))[0].rows; + try std.testing.expectEqual(@as(usize, 2), got.len); + const code = [2][]const u8{ "const x = 1;", "fn y() void {}" }; + var col: [2]usize = undefined; + for (got, code, &col) |row, text, *c| { + const at = std.mem.indexOf(u8, row.text, text).?; + c.* = File.displayWidth(8, row.text[0..at]); + // The place dim up to its blank (`path:3:1`); the text after it not. + try std.testing.expect(row.pre > 0); + try std.testing.expectEqual(@as(u16, 0), row.quiet[0]); + try std.testing.expectEqual(':', row.text[row.quiet[1] - 2]); + try std.testing.expectEqual(' ', row.text[row.quiet[1]]); + } + try std.testing.expectEqual(col[0], col[1]); + // One cell after the widest place. + try std.testing.expectEqual(File.displayWidth(8, b_path) + ":1:4 ".len, col[1]); +} diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index e7814fb5..c0e3f076 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -70,8 +70,8 @@ == snap list grid=180x31 cursor=110,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 1/3 |17: ls │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes … -|18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b |20: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c |21: │ │ |22: 1 l1 @@ -85,8 +85,8 @@ |30: ⏎ lands here · its text is the preview · S-⏎ a new pane 1 message · SPC h m == snap ctrln grid=180x31 cursor=110,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 -|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b |22: 3 l3 |23: 4 l4 |24: 5 l5 diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 5d536a0f..c680700d 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -59,8 +59,8 @@ == snap symbols grid=120x41 cursor=24,2 |2: ^ a.zig:8 › ␣ l Symbols 1/3 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes Symbols All Jumplist -|4: │ │ ▶ a.zig:1:7-9 std -|5: │ │ a.zig:3:4-9 helper +|4: │ │ ▶ a.zig:1:7-9 std +|5: │ │ a.zig:3:4-9 helper |6: │ │ a.zig:7:8-11 main |7: │ │ |8: 1▸const std = @import("std"); |
