fix rounding

This commit is contained in:
Andrew Pareles 2024-12-23 04:33:49 -08:00
parent 372beb7a2d
commit ffe5a41b01

View file

@ -890,8 +890,15 @@ Please finish writing the new file by applying the diff to the original file. Re
// |B <-- deleted here, diff.startLine == diff.endLine
// C
if (diff.type === 'deletion') {
writeText = diff.originalCode + '\n'
toRange = { startLineNumber: diff.startLine, startColumn: 1, endLineNumber: diff.startLine, endColumn: 1 }
// if startLine is out of bounds (deleted lines past the diffarea), applyEdit will do a weird rounding thing, to account for that we apply the edit the line before
if (diff.startLine - 1 === diffArea.endLine) {
writeText = '\n' + diff.originalCode
toRange = { startLineNumber: diff.startLine - 1, startColumn: Number.MAX_SAFE_INTEGER, endLineNumber: diff.startLine - 1, endColumn: Number.MAX_SAFE_INTEGER }
}
else {
writeText = diff.originalCode + '\n'
toRange = { startLineNumber: diff.startLine, startColumn: 1, endLineNumber: diff.startLine, endColumn: 1 }
}
}
// if it was an insertion, need to delete all the lines
// (this image applies to writeText and toRange, not newOriginalCode)