diff options
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" { |
