From 26649273cc253319fdd833923928aa883e3f884c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 00:10:03 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/File.zig | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/File.zig') 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" { -- cgit v1.3