diff options
Diffstat (limited to 'core/syntax.zig')
| -rw-r--r-- | core/syntax.zig | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/core/syntax.zig b/core/syntax.zig index 1bb8fb52..08ea1fb4 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -1014,6 +1014,17 @@ pub fn highlightDiff(gpa: std.mem.Allocator, content: []const u8, start_raw: usi /// The same for a terminal's rows, where a row the terminal wrapped /// continues the diff line above it. pub fn highlightDiffRows(gpa: std.mem.Allocator, content: []const u8, start_raw: usize, end_raw: usize, continued_rows: bool) ![]u8 { + return diffStyles(gpa, content, start_raw, end_raw, continued_rows, true); +} + +/// `highlightDiff` without the language's ink: each hunk line in one +/// colour as a file in no language pardes knows has it, the grounds, markers +/// and changed words as they are (a patch's pane with `Syntax` off). +pub fn highlightDiffPlain(gpa: std.mem.Allocator, content: []const u8, start_raw: usize, end_raw: usize) ![]u8 { + return diffStyles(gpa, content, start_raw, end_raw, false, false); +} + +fn diffStyles(gpa: std.mem.Allocator, content: []const u8, start_raw: usize, end_raw: usize, continued_rows: bool, language: bool) ![]u8 { const tz = tracy.zone(@src(), "highlightDiff"); defer tz.end(); const start_byte = @min(start_raw, content.len); @@ -1041,7 +1052,7 @@ pub fn highlightDiffRows(gpa: std.mem.Allocator, content: []const u8, start_raw: else => false, }; if (piece_start) |ps| if (!body or nkinds == diff_piece_cut) { - if (piece_end >= start_byte) try paintDiffPiece(gpa, window, content[ps..piece_end], ps, kinds[0..nkinds], piece_path); + if (piece_end >= start_byte) try paintDiffPiece(gpa, window, content[ps..piece_end], ps, kinds[0..nkinds], piece_path, language); piece_start = null; nkinds = 0; }; @@ -1066,7 +1077,7 @@ pub fn highlightDiffRows(gpa: std.mem.Allocator, content: []const u8, start_raw: at = nl + 1; } if (piece_start) |ps| if (piece_end >= start_byte) - try paintDiffPiece(gpa, window, content[ps..piece_end], ps, kinds[0..nkinds], piece_path); + try paintDiffPiece(gpa, window, content[ps..piece_end], ps, kinds[0..nkinds], piece_path, language); return styles; } @@ -1087,8 +1098,8 @@ const DiffWindow = struct { } }; -fn paintDiffPiece(gpa: std.mem.Allocator, window: DiffWindow, bytes: []const u8, at: usize, kinds: []const diff.Kind, path: []const u8) !void { - const selected: ?Selected = if (syntax_started) (forExt(std.Io.Dir.path.extension(path)) catch null) else null; +fn paintDiffPiece(gpa: std.mem.Allocator, window: DiffWindow, bytes: []const u8, at: usize, kinds: []const diff.Kind, path: []const u8, language: bool) !void { + const selected: ?Selected = if (language and syntax_started) (forExt(std.Io.Dir.path.extension(path)) catch null) else null; if (selected) |sel| { const hash = std.hash.Wyhash.hash(std.hash.Wyhash.hash(0, sel.name), bytes); diff_clock += 1; |
