diff options
| -rw-r--r-- | src/File.zig | 98 |
1 files changed, 61 insertions, 37 deletions
diff --git a/src/File.zig b/src/File.zig index e387abab..c80e5c42 100644 --- a/src/File.zig +++ b/src/File.zig @@ -2253,48 +2253,72 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const grapheme_end = @min(limit, modal.nextGrapheme(line, hs + c)); const cells = graphemeDisplayWidth(line[hs + c .. grapheme_end]); const idx = base + hs + c; - // What paints the grapheme's cells, in this order: its syntax - // colour (a diff line's prefix its tint's ink), the words a diff - // changed on their stronger ground, a result's emphasis (only - // the location, matched source range and diagnostic label gain - // it: results keep their exact live text), a +Pager's colours. - const highlight: ?u8 = if (idx >= highlight_start and idx - highlight_start < highlights.len) highlights[idx - highlight_start] else null; - const syn = if (highlight) |h| (if (tint != null and hs + c == 0) SynStyle{ .fg = tint.?.fg, .bold = true } else synStyle(p, @fromBackingInt(@intCast(h & syntax.syn_bits)))) else null; - const emph = if (highlight != null and tint != null and highlight.? & syntax.diff_emph != 0) tint.?.emph_bg else null; - const deco = if (chrome) |ch| decoration.styleAt(ch, hs + c) else null; - while (span_at < spans.len and spans[span_at].end <= idx) span_at += 1; - const span = if (span_at < spans.len and spans[span_at].start <= idx) spans[span_at].style else null; - for (0..@min(cells, @as(usize, tw) - prefix_width - screen_c)) |fill| { - const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); - if (!cell.default) if (syn) |ss| { - cell.style.fg = .{ .rgb = ss.fg }; - cell.style.bold = ss.bold; - }; - if (emph) |bg| cell.style.bg = .{ .rgb = bg }; - if (cell.default) continue; - if (deco) |style| { + // Each painter (the syntax colour, a diff's emphasis ground, a + // result's emphasis, a +Pager's colours) loops over the cells + // only when it paints: one loop asking all four on every cell + // cost the frame a sixth more instructions (zig build perf, + // render on the medium file). + if (idx >= highlight_start) { + const hidx = idx - highlight_start; + if (hidx < highlights.len) { + if (if (tint != null and hs + c == 0) + SynStyle{ .fg = tint.?.fg, .bold = true } + else + synStyle(p, @fromBackingInt(@intCast(highlights[hidx] & syntax.syn_bits)))) |ss| + { + var fill: usize = 0; + while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { + const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); + if (cell.default) continue; + cell.style.fg = .{ .rgb = ss.fg }; + cell.style.bold = ss.bold; + } + } + if (tint) |t| if (highlights[hidx] & syntax.diff_emph != 0) { + var fill: usize = 0; + while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) + s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr).style.bg = .{ .rgb = t.emph_bg }; + }; + } + } + // Results keep their exact live text. Only the location, + // matched source range and diagnostic label gain emphasis. + if (if (chrome) |ch| decoration.styleAt(ch, hs + c) else null) |style| { + var fill: usize = 0; + while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { + const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); + if (cell.default) continue; cell.style.fg = style.fg; cell.style.bold = style.bold; if (style.bg != .default) cell.style.bg = style.bg; } - const st = span orelse continue; - // As a terminal pane's cell: through Filter, or a palette - // colour through the theme's sixteen and truecolor as it is. - if (filtered) |colors| { - if (st.fg != .default) cell.style.fg = colors.spanColor(st.fg, false); - if (st.bg != .default) cell.style.bg = colors.spanColor(st.bg, true); - } else { - if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg; - if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg; + } + while (span_at < spans.len and spans[span_at].end <= idx) span_at += 1; + if (span_at < spans.len and spans[span_at].start <= idx) { + const st = spans[span_at].style; + var fill: usize = 0; + while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { + const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); + if (cell.default) continue; + // As a terminal pane's cell: through Filter, or a + // palette colour through the theme's sixteen and + // truecolor as it is. + if (filtered) |colors| { + if (st.fg != .default) cell.style.fg = colors.spanColor(st.fg, false); + if (st.bg != .default) cell.style.bg = colors.spanColor(st.bg, true); + } else { + if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg; + if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg; + } + cell.style.bold = cell.style.bold or st.bold; + cell.style.dim = st.dim; + cell.style.italic = st.italic; + cell.style.blink = st.blink; + cell.style.reverse = st.reverse; + cell.style.invisible = st.invisible; + cell.style.strikethrough = st.strikethrough; + if (st.ul != .off) cell.style.ul = st.ul; } - cell.style.bold = cell.style.bold or st.bold; - cell.style.dim = st.dim; - cell.style.italic = st.italic; - cell.style.blink = st.blink; - cell.style.reverse = st.reverse; - cell.style.invisible = st.invisible; - cell.style.strikethrough = st.strikethrough; - if (st.ul != .off) cell.style.ul = st.ul; } screen_c += cells; c = grapheme_end - hs; |
