insert_content: align right buffer newline with display-normalized left to prevent false deletion at EOF append

This commit is contained in:
Hannes Rudolph 2025-11-11 13:20:38 -07:00
parent a398b578ea
commit 2b4a614260

View file

@ -175,8 +175,11 @@ export class DiffViewProvider {
await vscode.workspace.applyEdit(edit)
}
// Preserve empty last line if original content had one.
const hasEmptyLastLine = this.originalContent?.endsWith("\n")
// Preserve empty last line if the ORIGINAL DISPLAY BUFFER had one.
// We normalize the left side (original) to include a trailing newline for display
// when the file lacks it. To avoid spurious deletion on EOF-append, keep the
// right side consistent with that display buffer as well.
const hasEmptyLastLine = (this.originalContentForDisplay ?? this.originalContent)?.endsWith("\n")
if (hasEmptyLastLine && !accumulatedContent.endsWith("\n")) {
accumulatedContent += "\n"