Skip to content

Commit 9767446

Browse files
committed
Prevent the use of stale editors during undo operations by tracking file relocation status
1 parent 8c53295 commit 9767446

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/utils/file-operations.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,15 @@ export const undo_files = async (params: {
400400
}
401401
}
402402
} else {
403+
let file_was_relocated = false
403404
if (state.file_path_to_restore) {
404405
if (safe_path && (await uri_exists(vscode.Uri.file(safe_path)))) {
405406
await relocate_file({
406407
old_path: state.file_path,
407408
new_path: state.file_path_to_restore,
408409
workspace_root
409410
})
411+
file_was_relocated = true
410412
}
411413
safe_path = create_safe_path(
412414
workspace_root,
@@ -449,9 +451,11 @@ export const undo_files = async (params: {
449451
}
450452
} else {
451453
try {
452-
const editor = vscode.window.visibleTextEditors.find(
453-
(e) => e.document.uri.fsPath == safe_path
454-
)
454+
const editor = !file_was_relocated
455+
? vscode.window.visibleTextEditors.find(
456+
(e) => e.document.uri.fsPath == safe_path
457+
)
458+
: undefined
455459
if (editor) {
456460
const document = editor.document
457461
await editor.edit((edit) => {

0 commit comments

Comments
 (0)