diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/draw.zig | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/core/draw.zig b/core/draw.zig index 822bfb67..0946978f 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -1121,6 +1121,15 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, } 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), chrome.name[@intFromEnum(g)], false); + // While its body previews a file not its own (a picker's: its own set + // aside, or a kind shown over it), its path names a file the body is + // not showing: the dim ink (the coordinator's ruling, UX DESIGN M7.2). + if (pardes.Pick.previewing(p, id)) if (pardes.Pick.live(p)) |pk| { + const own = if (pk.aside) |f| f.path else if (pane.file) |f| f.path else ""; + const body = if (pane.addon) |k| k.path else if (pane.file) |f| f.path else ""; + if (!std.mem.eql(u8, own, body)) if (tagTintRange(p, pane, first_line, prefix_len)) |name| + inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, tagline.nameAt(p, pane), @min(name.hi, first_line.len), inks.dim, 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); @@ -1953,3 +1962,65 @@ test "a reading pane's tag is on the plain or the focused ground, as a held one' }; } } + +test "while a pane's body previews a file not its own, its tag's path is dim: it names a file the body is not showing (the coordinator's ruling, UX DESIGN M7.2); its own file previewed, or the picker gone, the path in its inks again" { + 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(); + for ([_][]const u8{ "alpha.zig", "beta.zig" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "one\ntwo\n" }); + var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; + const a_path = try std.Io.Dir.path.join(std.testing.allocator, &.{ dir, "alpha.zig" }); + defer std.testing.allocator.free(a_path); + pardes.look.lookAt(p, p.view().active, a_path); + p.sync(); + const id = p.view().active; + const pane = p.panes[id].?; + p.newScratchBelow(id); + const other = p.view().active; + p.view().active = id; + pardes.Pick.open(p, id, .list, "Refs", "", "beta.zig:2:1 two\nalpha.zig:1:1 one\n"); + for (0..4) |_| { + pardes.Stream.step(p); + p.update(.tick); + } + try std.testing.expect(pardes.Pick.previewing(p, id) and std.mem.endsWith(u8, pane.file.?.path, "beta.zig")); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const Path = struct { + // The tag at rest (its tag state hosted by another pane, as a + // picker under a tag at rest is): the ink of its path's first and + // last cells. + fn inks(q: *Pardes, a: std.mem.Allocator, at: usize, away: usize) ![2]Color { + const host = q.view().tag_state.host; + q.view().tag_state.host = q.panes[away].?.serial; + defer q.view().tag_state.host = host; + const s = try q.render(a); + const t = q.panes[at].?; + const r = q.view().rects[at]; + const lo = tagline.nameAt(q, t); + const path = t.file.?.path; + const x = r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(q.settings.tab, (try tagline.tagText(q, a, t))[0..lo]))); + return .{ s.at(x, r.y).style.fg, s.at(x + @as(u16, @intCast(panes.File.displayWidth(q.settings.tab, path))) - 1, r.y).style.fg }; + } + }; + const inks = p.chrome().on(.focus); + for (try Path.inks(p, frame.allocator(), id, other)) |ink| try std.testing.expectEqual(Color{ .rgb = inks.dim }, ink); + // Its own file under the cursor: the path names what the body shows. + p.update(.{ .key = .{ .cp = pardes.Key.down } }); + for (0..4) |_| { + pardes.Stream.step(p); + p.update(.tick); + } + try std.testing.expectEqualStrings(a_path, pane.file.?.path); + var got = try Path.inks(p, frame.allocator(), id, other); + try std.testing.expectEqual(Color{ .rgb = inks.text }, got[0]); + try std.testing.expectEqual(Color{ .rgb = p.chrome().name[1] }, got[1]); + // The picker gone: its own again. + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(!pardes.Pick.previewing(p, id)); + got = try Path.inks(p, frame.allocator(), id, other); + try std.testing.expectEqual(Color{ .rgb = inks.text }, got[0]); +} |
