From 2b4a614260dce7e916b608d107a3560c031eabe3 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Tue, 11 Nov 2025 13:20:38 -0700 Subject: [PATCH] insert_content: align right buffer newline with display-normalized left to prevent false deletion at EOF append --- src/integrations/editor/DiffViewProvider.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 678b574a92..e19f275bef 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -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"