diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:10:03 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:16:28 -0300 |
| commit | 26649273cc253319fdd833923928aa883e3f884c (patch) | |
| tree | 15425d5aa13a6643ce0fbb41c483077005fb7b1e /src/File.zig | |
| parent | e5c10e836cbcc2f3409eb709683aba8a780d7ce7 (diff) | |
| download | pardes-26649273cc253319fdd833923928aa883e3f884c.tar.gz pardes-26649273cc253319fdd833923928aa883e3f884c.zip | |
File: a +Pager's text is told a diff by diff.looksLikeDiff, the one heuristic command panes use (a diff --git line, or a ---/+++ pair over a valid @@ hunk, in the first 200 lines), not by a second one of its own (visible: a pager text with a diff line but no unified hunk, or ---/+++/@@ lines apart, is no longer shown as a diff)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/File.zig')
| -rw-r--r-- | src/File.zig | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/File.zig b/src/File.zig index 8e976895..962c17e7 100644 --- a/src/File.zig +++ b/src/File.zig @@ -1183,13 +1183,14 @@ pub fn syncTwins(p: *Pardes) void { } } -/// Whether `head`, a text's first bytes, holds a diff: a `diff` header, or -/// a unified hunk's `---`, `+++` and `@@` lines. +/// Whether `head`, a text's first bytes, holds a diff, as a command pane's +/// rows are told one (diff.looksLikeDiff, its first 200 lines). pub fn looksLikeDiff(head: []const u8) bool { - if (std.mem.startsWith(u8, head, "diff ") or std.mem.indexOf(u8, head, "\ndiff ") != null) return true; - const minus = std.mem.indexOf(u8, head, "--- ") orelse return false; - const plus = std.mem.indexOfPos(u8, head, minus, "\n+++ ") orelse return false; - return std.mem.indexOfPos(u8, head, plus, "\n@@ ") != null; + var lines: [200][]const u8 = undefined; + var it = std.mem.splitScalar(u8, head, '\n'); + var n: usize = 0; + while (n < lines.len) : (n += 1) lines[n] = it.next() orelse break; + return diff.looksLikeDiff(lines[0..n]); } test "a +Pager pane holding a diff is drawn and looked at as one; holding other text, as text" { |
