summaryrefslogtreecommitdiff
path: root/core/syntax.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 07:02:01 -0300
committerGabriel Schneider <[email protected]>2026-11-21 07:02:01 -0300
commitf7de6f49ee3d9ac241575f5244743193c9943841 (patch)
tree9f77af1eab8bfba6a4c8cfc75fe5ec646d517ffe /core/syntax.zig
parent78a022adb2a657711f706fcaae7c2abb412dac9c (diff)
downloadpardes-f7de6f49ee3d9ac241575f5244743193c9943841.tar.gz
pardes-f7de6f49ee3d9ac241575f5244743193c9943841.zip
layers: what round 1 left, three places where a revision's pane or a patch's did not do what the design's words say: a B3 click on path@rev[:line] in running text opens the file at that revision there (the click already expanded the whole token, @ being a file character; jj's test now drives it through the mouse); a revision's text is read-only over 9P too: an open of its body, data, xdata or sel to write is refused in words ("a revision is read-only", errno EROFS, as enameErrno reads the words: core/ninep/tree.zig's open, the one road 9P has to the text; the editor's own two are File.edit's splice and edit.zig's whole text), where before the write reached File.edit and was answered "out of memory"; Syntax off in a patch's pane takes the language's ink and leaves the patch: its bytes are made again once a paint without the language's (syntax.highlightDiffPlain), grounds, markers and changed words as they were (round 1 took them too); tests: the click, the four opens, a .zig patch's cells' grounds the same and its ink not; tui core-test 893/1053 (160 skipped)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/syntax.zig')
-rw-r--r--core/syntax.zig19
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;