summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig57
1 files changed, 51 insertions, 6 deletions
diff --git a/core/File.zig b/core/File.zig
index 01aaeec8..450e4ec9 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -1864,8 +1864,8 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
/// highlightFileRange): on until `Syntax` turns it off;
/// 2. patch: a diff's or a patch's grounds, a `+`/`-` row's ground and
/// marker and the words a changed line changed (syntax.zig's
-/// highlightDiff): always, in a diff (its style bytes are the ink's
-/// too: `Syntax` off takes both).
+/// highlightDiff): always, in a diff (with `Syntax` off its bytes are
+/// made without the language's ink: highlightDiffPlain).
///
/// Both are painted in recolorSyntax's one walk over the cells, each where
/// it says (one walk per painter cost a frame a sixth more). Ruled, not
@@ -1886,10 +1886,16 @@ pub fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle {
/// syntax colors: recolor each content cell from its tree-sitter style byte;
/// content starts after the lineno gutter
pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void {
- // The ink off (`Syntax`): no style byte is read, so a cell asks
- // nothing of it (a test a cell cost a frame 0.1 to 0.5%). A patch's
- // grounds are bytes of the same painter's: they go with it.
- const highlights: []const u8 = if (!pane.layers.ink) &.{} else if (f.mini) |mini| mini.colors else f.highlights;
+ // The ink off (`Syntax`): a file's style bytes are not read, so a cell
+ // asks nothing of it (a test a cell cost a frame 0.1 to 0.5%); a
+ // patch's are made again without the language's, once a paint, its
+ // grounds, markers and changed words kept.
+ const highlights: []const u8 = if (pane.layers.ink)
+ (if (f.mini) |mini| mini.colors else f.highlights)
+ else if (pane.colorAlgo() == .diff and f.highlights.len > 0)
+ syntax.highlightDiffPlain(p.scratch.allocator(), f.content, f.highlight_start, f.highlight_start + f.highlights.len) catch &.{}
+ else
+ &.{};
const highlight_start = if (f.mini != null) 0 else f.highlight_start;
const spans = f.pager_spans;
if (highlights.len == 0 and f.output == null and spans.len == 0) return;
@@ -2614,3 +2620,42 @@ test "Syntax takes a text's ink off in this view and puts it back, and another v
try Frame.take(p, &arena, pane, id, &inks);
try std.testing.expect(Frame.colored(&inks, plain));
}
+
+test "Syntax off in a patch's pane takes the language's ink and leaves the patch: every ground as it was" {
+ if (!syntax.supportsPath("/x.zig")) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ // A patch's hunks take their language's ink once the parsers run.
+ syntax.start(gpa);
+ defer syntax.stop();
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 14 });
+ defer p.deinit();
+ const pane = try p.setTestFile("diff --git a/x.zig b/x.zig\n--- a/x.zig\n+++ b/x.zig\n@@ -1,2 +1,2 @@\n const a = 1;\n-const b = 2;\n+pub const b = 3;\n");
+ gpa.free(pane.file.?.path);
+ pane.file.?.path = try gpa.dupe(u8, "/change.diff");
+ pane.file.?.syntax_dirty = true;
+ try std.testing.expect(pane.colorAlgo() == .diff);
+ const id = p.view().active;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var on: [7][2][24]pardes.Color = undefined;
+ for (0..2) |pass| {
+ if (pass == 1) p.update(.{ .command = "Syntax" });
+ p.sync();
+ _ = arena.reset(.retain_capacity);
+ const s = try p.render(arena.allocator());
+ const body = s.region(.body, id).?.rect;
+ var differ = false;
+ for (0..7) |row| for (0..24) |col| {
+ const cell = s.cells[(body.y + row) * s.cols + body.x + gutterWidth(pane) + col];
+ if (pass == 0) {
+ on[row][0][col] = cell.style.bg;
+ on[row][1][col] = cell.style.fg;
+ } else {
+ // The grounds stay; the ink of the code goes.
+ try std.testing.expect(std.meta.eql(on[row][0][col], cell.style.bg));
+ differ = differ or !std.meta.eql(on[row][1][col], cell.style.fg);
+ }
+ };
+ if (pass == 1) try std.testing.expect(differ);
+ }
+}