Skip to content

fix: prevent incorrect merge of content-identical lines across non-monotonic crossings - #374

Merged
glehmann merged 1 commit into
mainfrom
gln/diff-merge-logic-fix-plyn
Jul 30, 2026
Merged

fix: prevent incorrect merge of content-identical lines across non-monotonic crossings#374
glehmann merged 1 commit into
mainfrom
gln/diff-merge-logic-fix-plyn

Conversation

@glehmann

Copy link
Copy Markdown
Collaborator

When a multi-line block is restructured (lines moved between blocks),
content-identical lines at different old/new positions were incorrectly
merged into context lines, causing duplicated content, missing lines,
and non-monotonic line numbers in both unified and split diff views.

Two root causes fixed:

  1. mergeModifiedLines second pass re-paired content-identical deletes
    with inserts after detectAndUnpairCrossings intentionally un-paired
    them. Now prevents crossing pairs unless the unpaired lines form a
    complete permutation (rotation of identical content).

  2. lookupOldHtml used full-file highlighted content indexed by old line
    number for delete lines, but the fetched file content can diverge
    from the diff's line numbering. Delete lines now highlight directly
    from their segment value.

Also adds cache-busting to the diff worker URL to prevent stale worker
caching during development.

…notonic crossings

When a multi-line block is restructured (lines moved between blocks),
content-identical lines at different old/new positions were incorrectly
merged into context lines, causing duplicated content, missing lines,
and non-monotonic line numbers in both unified and split diff views.

Two root causes fixed:

1. mergeModifiedLines second pass re-paired content-identical deletes
   with inserts after detectAndUnpairCrossings intentionally un-paired
   them. Now prevents crossing pairs unless the unpaired lines form a
   complete permutation (rotation of identical content).

2. lookupOldHtml used full-file highlighted content indexed by old line
   number for delete lines, but the fetched file content can diverge
   from the diff's line numbering. Delete lines now highlight directly
   from their segment value.

Also adds cache-busting to the diff worker URL to prevent stale worker
caching during development.
@glehmann
glehmann merged commit 23690c4 into main Jul 30, 2026
6 checks passed
@glehmann
glehmann deleted the gln/diff-merge-logic-fix-plyn branch July 30, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant