Repository navigation
Undo the file operations of a workspace edit in reverse order - #344772
Marcus Lagergren (lagergren) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active issues were found, and the localized reverse-order fix is accompanied by focused new tests covering the dependent file-operation scenarios without regressing existing behavior.
No open issues 🎉
What changed in this PR
This PR fixes issue #344765, where undoing a WorkspaceEdit that moves a file out of a folder and then renames that folder failed with "target already exists". The root cause was that both FileUndoRedoElement._reverse() and RenameOperation.perform() applied inverse operations in their original (forward) order. When operations are dependent, the inverse must run in reverse order (undo the later operation first). The fix is localized to src/vs/workbench/contrib/bulkEdit/browser/bulkFileEdits.ts.
I traced both the inter-operation reversal (backward loop + operations.reverse() to keep redo replaying in the original order) and the intra-rename reversal (undoes.reverse()), and confirmed they operate on orthogonal dimensions and compose correctly across repeated undo/redo cycles. The change is conservative: reverse order is required for dependent operations and harmless for independent ones, so no pre-existing single-operation behavior (including the existing delete/restore ordering tests) regresses.
Changes:
FileUndoRedoElement._reverse()now performs inverses from last to first and reverses the operations array afterward, so undo runs in reverse order while redo replays in the original order.RenameOperation.perform()reverses its collected inverse moves so a rename group's dependent moves are undone in reverse order.- Adds two focused tests covering dependent moves within one rename operation and across two operations, each asserting the apply/undo/redo sequence.
| File | Description |
|---|---|
src/vs/workbench/contrib/bulkEdit/browser/bulkFileEdits.ts |
Undo operations and inverse rename moves in reverse order, reversing back so redo preserves the original order. |
src/vs/workbench/contrib/bulkEdit/test/browser/bulkFileEdits.test.ts |
Adds an applyUndoRedo helper and two tests verifying reverse-order undo for dependent file operations. |
No objective issues were found; the change is correct, well-scoped, and covered by new tests that follow the file's existing patterns and conventions.
Review effort: Balanced
a19bc2a to
ef37349
Compare
Undo and Redo of a workspace edit's file operations performed the inverse operations in their original order, and a rename operation collected its inverse moves in that order too. When one operation depends on an earlier one, as when a file moves out of a folder that is renamed after it, Undo moved the file back first, which created the old folder again, and the folder could then not be renamed back: "target already exists". FileUndoRedoElement now undoes the operations from the last to the first, and reverses their inverses, so that Redo performs them in the original order again. A rename operation's inverse undoes its moves in reverse order. Fixes microsoft#344765
ef37349 to
8e0a7cd
Compare
Fixes #344765
Undo and Redo of a workspace edit's file operations performed the inverse operations in their original order (
FileUndoRedoElement._reverse()), andRenameOperation.perform()collected its inverse moves in that order too. When one operation depends on an earlier one, as when a file moves out of a folder that is renamed after it, Undo moved the file back first. That created the old folder again, so the folder could then not be renamed back: "target already exists".FileUndoRedoElementundoes the operations from the last to the first, and reverses their inverses, so that Redo performs them in the original order again.The inverses of copy, create and delete operations keep their order. Within one operation, their order matters only for nested paths, and an existing test checks the order in which Undo recreates deleted files.
Tests, in
bulkFileEdits.test.ts, check the file operations of an edit, its Undo and its Redo:Both fail without the change, and the existing
BulkFileEditstests pass with it. Run with./scripts/test.sh --grep 'BulkFileEdits|Files - 'onmain915c6faed9c: 344 passing. ESLint reports nothing for the changed files.