FIX: Fix chunk expansion for insertions at end of document #8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-fromline-boundary-bug"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When a change is a pure insertion at the end of a document (
fromA == a.length),fromLinefalls back to[lineA.from, lineB.from], expanding the chunk to cover the entire last line. This causes the unified merge view to mark unchanged content as part of the diff.Reproduction
Diff
"hello"against"hello\nworld"usingunifiedMergeView. The entire first linehellois shown as both deleted and inserted, instead ofworldbeing a clean insertion.Fix
In
fromLine, the conditionfromA < a.length && fromB < b.lengthprevents advancing past the line end when either document has ended. But for insertions at document end, we should still advance if the position is at the end of a non-empty line (not the start of an empty trailing line).The added check
lineA.from < fromA || lineB.from < fromBdistinguishes between:lineA.from < fromA) → advance to next linelineA.from == fromA) → stay (existing behavior)This behavior is intentional. Our chunk representation assumes every chunk starts on the start of a line, and chunks that start beyond the end of the document will break some of the other code. If we're considering the newline/eof after a line to be part of the line, the inclusion of that first line in your reproduction case in the chunk even more or less makes sense.
Pull request closed