diff options
Diffstat (limited to 'addons/pdf')
| -rw-r--r-- | addons/pdf/pdf.zig | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig index 7ee3400a..a401c979 100644 --- a/addons/pdf/pdf.zig +++ b/addons/pdf/pdf.zig @@ -405,7 +405,7 @@ pub const Pdf = extern struct { // white tinted is the theme's paper const paper: u32 = if (st.tint == .disabled) 0xffffff else if (pixels(st, st.active)) |a| @backingInt(a.v.bg) else 0xffffff; o.blank = .{ @truncate(paper >> 16), @truncate(paper >> 8), @truncate(paper), 255 }; - reconcile(st, o, l, sp, win.view); + reconcile(st, o, l, sp, win); const vh = @min(@as(u32, win.rows) * win.cell_h, l.vh); const first, const count = visible(st, l, sp); for (first..first + count) |p| { @@ -1377,9 +1377,10 @@ fn rasterOf(st: *const Pdf, o: *Own, p: usize, q: Request) [2]u32 { // ---- highlights ---- -/// Page `p`'s highlights in view `l`, as painted: the pointer's, the -/// search's, the selection's. -fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark) []Mark { +/// Page `p`'s highlights in view `l`, as painted in `win`: the pointer's, +/// the search's (in the theme's hit colours, the current hit apart), the +/// selection's. +fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark, win: addon.Window) []Mark { const f = struct { fn mark(q: Quad, rgb: u32, a: u8, kind: c_int) Mark { return .{ .quad = q, .rgba = .{ @truncate(rgb >> 16), @truncate(rgb >> 8), @truncate(rgb), a }, .kind = kind }; @@ -1393,7 +1394,7 @@ fn marksOf(st: *const Pdf, o: *Own, l: *const Layout, p: u32, out: []Mark) []Mar if (st.find.hits_page == p) { const hits = hitsOf(st, o); for (hits[0..@min(hits.len, out.len - n)]) |h| { - out[n] = f.mark(h.quad, 0xffd54f, 0x70, m.PARDES_PDF_HIGHLIGHT_SEARCH); + out[n] = f.mark(h.quad, @backingInt(if (h.hit == st.find.hit) win.hit_current else win.hit), 0x70, m.PARDES_PDF_HIGHLIGHT_SEARCH); n += 1; } } @@ -1528,10 +1529,11 @@ fn repaint(o: *Own, s: *Slot, now: []const Mark) bool { return keepMarks(&s.shown, now); } -/// What view `id`'s window shows (and the page past it) made so, as it is -/// painted: pages gone dropped, highlights moved repainted, the rest asked -/// of the lanes as draws. -fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, id: u8) void { +/// What view `win.view`'s window shows (and the page past it) made so, as +/// it is painted: pages gone dropped, highlights moved repainted, the rest +/// asked of the lanes as draws. +fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, win: addon.Window) void { + const id = win.view; const first, var n = visible(st, l, sp); if (n > 0 and first + n < st.pages and !st.go.fling) n += 1; // the page ahead, at rest for (&o.s) |*s| if (s.view == id and (s.page < first or s.page >= first + n)) { @@ -1556,7 +1558,7 @@ fn reconcile(st: *const Pdf, o: *Own, l: *const Layout, sp: *const Strip, id: u8 const same = s.rgba.len > 0 and std.meta.eql(s.is.req, q); const wh = if (same) [2]u32{ s.is.w, s.is.h } else rasterOf(st, o, p, q); const y, const bh = bandOf(st, l, sp, p, wh[0], wh[1]); - const marks = marksOf(st, o, l, p, &now.at); + const marks = marksOf(st, o, l, p, &now.at, win); if (same and s.is.tint == st.tint and s.is.ink == @backingInt(l.v.fg) and s.is.paper == @backingInt(l.v.bg) and s.is.band_y <= y and s.is.band_y + s.is.band_h >= y + bh) { if (now.eq(s.shown, marks) or repaint(o, s, marks)) continue; } @@ -1860,3 +1862,22 @@ test "every pointer the bridge's structs hand back is read through addon.cSlice: }; } } + +test "a search's hits are marked in the theme's hit colours its window is painted with, the current hit in the current hit's (ABI 3.4)" { + var st: Pdf = .{}; + st.find.query[0] = 'x'; + st.find.len = 1; + st.find.hits_page = 0; + st.find.hit = 1; + // The page's hits as its search found them: the second, in two quads, current. + const q = std.mem.zeroes(Quad); + var quads = [_]m.pardes_pdf_search_quad{ .{ .quad = q, .hit = 0 }, .{ .quad = q, .hit = 1 }, .{ .quad = q, .hit = 1 } }; + var o: Own = .{ .hits = &quads, .hits_of = .{ .page = 0, .query = st.find.query } }; + var cells: [1]c.pa_cell = undefined; + const win: addon.Window = .{ .cells = &cells, .stride = 1, .cols = 1, .rows = 1, .cell_w = 8, .cell_h = 16, .focused = false, .view = 1, .glyphs = false, .hit = .rgb(0x4c, 0x30, 0x1a), .hit_current = .rgb(0xe5, 0x9d, 0x3c) }; + var out: [8]Mark = undefined; + const marks = marksOf(&st, &o, &st.views[0], 0, &out, win); + try std.testing.expectEqual(@as(usize, 3), marks.len); + try std.testing.expectEqual([4]u8{ 0x4c, 0x30, 0x1a, 0x70 }, marks[0].rgba); + for (marks[1..]) |mk| try std.testing.expectEqual([4]u8{ 0xe5, 0x9d, 0x3c, 0x70 }, mk.rgba); +} |
