diff view: normalize original buffer EOLs and force trailing newline for display; should remove single-line deletion in insert_content EOF append

This commit is contained in:
Hannes Rudolph 2025-11-11 13:22:34 -07:00
parent 2b4a614260
commit 494fc951ed

View file

@ -72,10 +72,10 @@ export class DiffViewProvider {
if (fileExists) {
this.originalContent = await fs.readFile(absolutePath, "utf-8")
// Normalize trailing newline for display only to avoid false replace of last line
this.originalContentForDisplay = this.originalContent.endsWith("\n")
? this.originalContent
: this.originalContent + "\n"
// Normalize EOLs to \n for display and ensure a trailing newline so
// the last unchanged line is treated as context instead of a replace.
const normalizedEol = this.originalContent.replace(/\r\n/g, "\n")
this.originalContentForDisplay = normalizedEol.endsWith("\n") ? normalizedEol : normalizedEol + "\n"
} else {
this.originalContent = ""
// For new files, keep original empty to show all additions