From 8798277c6ff838a67f109487a6598db29136d1fc Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Wed, 15 Apr 2026 07:14:14 +0800 Subject: [PATCH] fix: correct "to" line number in unified diff hunk headers When multiple edits within the same hunk were separated by equal lines, the equal lines added via addEqualLines in the "within range" case were not being counted in toLine. This caused subsequent hunk headers to report incorrect "to" line numbers. For example, a diff with two hunks where the first hunk had equal lines between its edits would produce: @@ -12,5 +10,5 @@ instead of the correct: @@ -12,5 +12,5 @@ Fix by accumulating the return value of addEqualLines into toLine for within-range equal lines, matching git diff behavior. Fixes #6 --- unified.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unified.go b/unified.go index b7d85cf..10f7e4b 100644 --- a/unified.go +++ b/unified.go @@ -99,7 +99,7 @@ func ToUnified(from, to string, content string, edits []TextEdit) Unified { //direct extension case h != nil && start <= last+gap: //within range of previous lines, add the joiners - addEqualLines(h, lines, last, start) + toLine += addEqualLines(h, lines, last, start) default: //need to start a new hunk if h != nil {