address heuristic when stage ranges act on same line number diff (#145899)

Co-authored-by: @lszomoru
Fixes: #126989
pull/147914/head
João Moreno 2022-04-22 12:31:15 +02:00 committed by GitHub
parent 90a6367e2c
commit 2e2654c97f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 6 deletions

View File

@ -109,12 +109,28 @@ export function intersectDiffWithRange(textDocument: TextDocument, diff: LineCha
if (diff.modifiedEndLineNumber === 0) {
return diff;
} else {
return {
originalStartLineNumber: diff.originalStartLineNumber,
originalEndLineNumber: diff.originalEndLineNumber,
modifiedStartLineNumber: intersection.start.line + 1,
modifiedEndLineNumber: intersection.end.line + 1
};
const modifiedStartLineNumber = intersection.start.line + 1;
const modifiedEndLineNumber = intersection.end.line + 1;
// heuristic: same number of lines on both sides, let's assume line by line
if (diff.originalEndLineNumber - diff.originalStartLineNumber === diff.modifiedEndLineNumber - diff.modifiedStartLineNumber) {
const delta = modifiedStartLineNumber - diff.modifiedStartLineNumber;
const length = modifiedEndLineNumber - modifiedStartLineNumber;
return {
originalStartLineNumber: diff.originalStartLineNumber + delta,
originalEndLineNumber: diff.originalStartLineNumber + delta + length,
modifiedStartLineNumber,
modifiedEndLineNumber
};
} else {
return {
originalStartLineNumber: diff.originalStartLineNumber,
originalEndLineNumber: diff.originalEndLineNumber,
modifiedStartLineNumber,
modifiedEndLineNumber
};
}
}
}