From 26f7d992082072e12eb1647d20288ec1a91b2d32 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:18:13 -0400 Subject: [PATCH] Fix new file creation --- src/ClaudeDev.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ClaudeDev.ts b/src/ClaudeDev.ts index b184299..b75bebe 100644 --- a/src/ClaudeDev.ts +++ b/src/ClaudeDev.ts @@ -892,11 +892,15 @@ export class ClaudeDev { // edit needs to happen after we close the original tab const edit = new vscode.WorkspaceEdit() - const fullRange = new vscode.Range( - updatedDocument.positionAt(0), - updatedDocument.positionAt(updatedDocument.getText().length) - ) - edit.replace(updatedDocument.uri, fullRange, newContent) + if (!fileExists) { + edit.insert(updatedDocument.uri, new vscode.Position(0, 0), newContent) + } else { + const fullRange = new vscode.Range( + updatedDocument.positionAt(0), + updatedDocument.positionAt(updatedDocument.getText().length) + ) + edit.replace(updatedDocument.uri, fullRange, newContent) + } // Apply the edit, but without saving so this doesnt trigger a local save in timeline history await vscode.workspace.applyEdit(edit) // has the added benefit of maintaing the file's original EOLs