summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:56:13 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:16:28 -0300
commit54b0c95fc5522b5ad48d857bb0a08c253c17ece3 (patch)
treee42bcebdf70a15e83a6a7b7ec6387698c90043cb
parent7b41b89dfb89e1a670baa50e14a892a9de0fa710 (diff)
downloadpardes-54b0c95fc5522b5ad48d857bb0a08c253c17ece3.tar.gz
pardes-54b0c95fc5522b5ad48d857bb0a08c253c17ece3.zip
File: recolorSyntax paints a grapheme's cells in one loop (syntax colour, a diff's emphasis ground, a result's emphasis, a pager's colours, in that order) instead of four loops over the same cells
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/File.zig93
1 files changed, 37 insertions, 56 deletions
diff --git a/src/File.zig b/src/File.zig
index 43eccc49..d2e8352a 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -1929,67 +1929,48 @@ 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;
- 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;
+ // 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| {
cell.style.fg = style.fg;
cell.style.bold = style.bold;
if (style.bg != .default) cell.style.bg = style.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;
+ 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;
}
+ 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;