Skip to content

Commit 7906320

Browse files
committed
fix(tools): Load original content before generating diff in background mode
Moved originalContent loading before diff generation to ensure proper diff comparison. Previously, the diff was being generated with empty originalContent, causing all lines to appear as additions.
1 parent 4693132 commit 7906320

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/core/tools/writeToFileTool.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ export async function writeToFileTool(
173173

174174
if (isPreventFocusDisruptionEnabled) {
175175
// Direct file write without diff view
176+
// Set up diffViewProvider properties needed for diff generation and saveDirectly
177+
cline.diffViewProvider.editType = fileExists ? "modify" : "create"
178+
if (fileExists) {
179+
const absolutePath = path.resolve(cline.cwd, relPath)
180+
cline.diffViewProvider.originalContent = await fs.readFile(absolutePath, "utf-8")
181+
} else {
182+
cline.diffViewProvider.originalContent = ""
183+
}
184+
176185
// Check for code omissions before proceeding
177186
if (detectCodeOmission(cline.diffViewProvider.originalContent || "", newContent, predictedLineCount)) {
178187
if (cline.diffStrategy) {
@@ -216,15 +225,6 @@ export async function writeToFileTool(
216225
return
217226
}
218227

219-
// Set up diffViewProvider properties needed for saveDirectly
220-
cline.diffViewProvider.editType = fileExists ? "modify" : "create"
221-
if (fileExists) {
222-
const absolutePath = path.resolve(cline.cwd, relPath)
223-
cline.diffViewProvider.originalContent = await fs.readFile(absolutePath, "utf-8")
224-
} else {
225-
cline.diffViewProvider.originalContent = ""
226-
}
227-
228228
// Save directly without showing diff view or opening the file
229229
await cline.diffViewProvider.saveDirectly(relPath, newContent, false, diagnosticsEnabled, writeDelayMs)
230230
} else {

0 commit comments

Comments
 (0)