summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig62
1 files changed, 52 insertions, 10 deletions
diff --git a/core/Query.zig b/core/Query.zig
index 2b2abebb..f3673dd6 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -471,8 +471,8 @@ fn makeNameRows(p: *Pardes, id: usize) !void {
var rows: std.ArrayList(locations.Row) = .empty;
var spans: std.ArrayList(pardes.Term.Span) = .empty;
errdefer spans.deinit(p.gpa);
- const chrome = p.bodyChrome();
- const tint: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.search_fg }, .bg = .{ .rgb = chrome.search_bg }, .bold = true };
+ const chrome = p.chrome();
+ const tint: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.page.text }, .bg = .{ .rgb = chrome.hit }, .bold = true };
const shown = @min(q.names.hits.items.len, Names.max_rows);
var marks: [Names.max_query * 4]u16 = undefined;
const base = lineOne(rp.file.?.content).len + 1;
@@ -510,7 +510,7 @@ fn makeNameRows(p: *Pardes, id: usize) !void {
// A closed pane's row is dimmer, the gutter's colour, between its
// marks (spans are walked in order, never overlapping).
const dim = q.source == .panes and p.paneBySerial(cand.ref) == null;
- const dimmed: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.lineno } };
+ const dimmed: pardes.CellStyle = .{ .fg = .{ .rgb = chrome.line_number } };
var gap: usize = 0;
var k: usize = 0;
while (k < nmarks) {
@@ -2092,8 +2092,7 @@ pub fn tagPrefix(q: *const Query, arena: std.mem.Allocator, path: []const u8) er
pub fn paintMark(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void {
const q = pane.query orelse return;
const c = q.current orelse return;
- const th = p.theme();
- const mark = colors.mix(th.bg orelse th.tag_bg, th.sel_bg);
+ const mark = p.chrome().selection_secondary;
const tx = r.x + config.GUTTER;
const tw = r.w -| config.GUTTER;
const col = File.gutterWidth(pane);
@@ -2106,13 +2105,11 @@ pub fn paintMark(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u
/// The other places on a hit row's line tinted, from the pane its rows are
/// in (the first is the row's own mark, Output.decorateRow): the current
-/// one strongest, as in that pane's text.
+/// one solid, as in that pane's text (Places.paint).
pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void {
const q = pane.query orelse return;
const f = if (pane.file) |*file| file else return;
- const th = p.theme();
- const strong = p.chromeTheme().search_bg;
- const quiet = colors.mix(th.bg orelse th.tag_bg, strong);
+ const c = p.chrome();
var vr: i32 = 0;
var last: i32 = -1;
while (vr < body_h) : (vr += 1) {
@@ -2144,7 +2141,7 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16)
const b = @min(line.len, meta.code_start + (@min(h.end, next) - ls - meta.source_column));
if (b <= a or a >= line.len) continue;
const current = set.current != null and set.current.? == hi;
- File.paintWordSelection(p, s, pane, r, row, @intCast(a), @intCast(b), if (current) strong else quiet);
+ File.paintWordSelection(p, s, pane, r, row, @intCast(a), @intCast(b), if (current) c.hit_current else c.hit, if (current) c.hit_current_text else null);
}
}
}
@@ -2815,3 +2812,48 @@ test "Grep: a row whose numbers a Found cannot hold (a column past u32) is passe
// Taken or passed over, each: never cast (main: Query.zig:1267).
try std.testing.expect(q.found.items.len <= 3);
}
+
+test "a query pane's hits are the body's: a row's match on the hit ground in the text's ink, the owner's current place solid in the hue with the page's ink, the current row marked with the selection's faint half" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .@"new-pane";
+ colors.setThemeIndex(p, colors.themeIndex("orchard").?);
+ const pane = try p.setTestFile("alpha one alpha\nbeta\ngamma alpha\n");
+ slash(p, "/alpha");
+ const qid = queryPane(p).?;
+ const qp = p.panes[qid].?;
+ try std.testing.expectEqual(@as(?usize, 0), qp.query.?.current);
+ try std.testing.expectEqual(@as(?usize, 0), pane.places.current);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const s = try p.render(frame.allocator());
+ const c = p.chrome();
+ const r = p.view().rects[qid];
+ // Row 1 (line 1 is the query) the first place's line, row 2 the third's.
+ var rows: [2][]const u8 = undefined;
+ for (&rows, 1..) |*row, k| {
+ var text: std.ArrayList(u8) = .empty;
+ for (0..r.w) |x| try text.appendSlice(frame.allocator(), s.at(r.x + @as(u16, @intCast(x)), p.bodyTop(qp, r) + @as(u16, @intCast(k))).grapheme());
+ row.* = text.items;
+ }
+ const y = p.bodyTop(qp, r) + 1;
+ const first = std.mem.indexOf(u8, rows[0], "alpha").?;
+ const second = std.mem.lastIndexOf(u8, rows[0], "alpha").?;
+ const third = std.mem.indexOf(u8, rows[1], "alpha").?;
+ try std.testing.expect(second > first + 5);
+ for (0..5) |i| {
+ const current = s.at(r.x + @as(u16, @intCast(first + 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(r.x + @as(u16, @intCast(second + i)), y).style;
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, other.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, other.fg);
+ const below = s.at(r.x + @as(u16, @intCast(third + i)), y + 1).style;
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, below.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.text }, below.fg);
+ }
+ // The current row's mark between its places and to its end; none below.
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.selection_secondary }, s.at(r.x + @as(u16, @intCast(first + 6)), y).style.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.selection_secondary }, s.at(r.x + r.w - 2, y).style.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = c.page.ground }, s.at(r.x + r.w - 2, y + 1).style.bg);
+}