diff options
Diffstat (limited to 'core/Places.zig')
| -rw-r--r-- | core/Places.zig | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/core/Places.zig b/core/Places.zig index 8563d7c8..63f9ced6 100644 --- a/core/Places.zig +++ b/core/Places.zig @@ -659,19 +659,17 @@ pub fn origin(set: *const Places, pane: *Pane) usize { } /// Every place on the rows shown, tinted over the text: the hit ground, -/// the current one the current hit's (colors.Roles, UX D4, D14). +/// the current one solid in the hue with the page's ink (R8, UX D14); a +/// search prompt's pattern that is no regex, its last places dimmed: the +/// current on the hit ground, the rest faint. pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void { if (!set.shows(pane)) return; const f = &pane.file.?; - const th = p.theme(); - const roles = &p.chromeTheme().roles; - var strong = roles.hit_current; - var quiet = roles.hit; - // A search prompt's pattern that is no regex: its last places, dimmed. - if (pardes.Prompt.dims(p, pane)) { - strong = quiet; - quiet = colors.mix(th.bg orelse th.tag_bg, quiet); - } + const c = p.chrome(); + const dim = pardes.Prompt.dims(p, pane); + const strong = if (dim) c.hit else c.hit_current; + const strong_ink: ?[3]u8 = if (dim) null else c.hit_current_text; + const quiet = if (dim) c.hit_faint else c.hit; const hits = set.hits.items; if (hits.len == 0) return; const nlines = File.nlines(p.gpa, f); @@ -697,7 +695,7 @@ pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, const b = @min(hits[i].end, le) - ls; if (b <= a) continue; const current = set.current != null and set.current.? == i; - File.paintWordSelection(p, s, pane, r, line, @intCast(a), @intCast(b), if (current) strong else quiet); + File.paintWordSelection(p, s, pane, r, line, @intCast(a), @intCast(b), if (current) strong else quiet, if (current) strong_ink else null); } } } @@ -903,3 +901,42 @@ test "a session's places loaded from its dump find what an edit makes as the ses b.panes[b.view().active].?.file.?.mtime = a.panes[a.view().active].?.file.?.mtime; try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b)); } + +test "places: each on the hit ground in its text's own ink, the current one solid, the hue its ground and the page its ink (R8, G7), the selection over it; a search whose field is no regex dims them, the rest faint" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + colors.setThemeIndex(p, colors.themeIndex("orchard").?); + const pane = try p.setTestFile("alpha beta\ngamma alpha\nb\nb\nb\nb\nb\nb\nb\nzeta alpha\n"); + // Landed on the first, the caret then moved off it: the places stay. + typeKeys(p, "/alpha"); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + typeKeys(p, "j"); + try std.testing.expect(pane.places.shows(pane)); + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + const c = p.chrome(); + var frame: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer frame.deinit(); + const r = p.view().rects[0]; + const x = r.x + pardes.config.GUTTER + File.gutterWidth(pane); + const y = p.bodyTop(pane, r); + var s = try p.render(frame.allocator()); + for (0..5) |i| { + const current = s.at(x + @as(u16, @intCast(i)), y).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_current }, current.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_current_text }, current.fg); + const other = s.at(x + 6 + @as(u16, @intCast(i)), y + 1).style; + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, other.bg); + try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, other.fg); + } + // Searched again from line 2: its place current and selected, the + // selection over the hit; then `(`, no regex: the others faint (line + // 10's: the prompt's words lie over the top rows). + typeKeys(p, "/alpha"); + try std.testing.expectEqual(@as(?usize, 1), pane.places.current); + s = try p.render(frame.allocator()); + for (0..4) |i| try std.testing.expectEqual(pardes.Color{ .rgb = c.page.selection.ground }, s.at(x + 6 + @as(u16, @intCast(i)), y + 1).style.bg); + typeKeys(p, "("); + try std.testing.expect(pardes.Prompt.dims(p, pane)); + s = try p.render(frame.allocator()); + for (5..10) |i| try std.testing.expectEqual(pardes.Color{ .rgb = c.hit_faint }, s.at(x + @as(u16, @intCast(i)), y + 9).style.bg); +} |
