project_panel: Confirm before trashing unsaved file on undo - #62294
Merged
Conversation
Update the way the `UndoManager` deals with trashing a file that has unsaved edits in order to avoid outright trashing the file and asking the user whether they'd like to save or discard the edits, or just cancel the operation. This helps avoid the issue where, if an user undoes a file creation for a file that has unsaved edits and then quits Zed, the edits that were saved in memory, as well as the Project Panel history, will now be gone and there's no way to recover the data.
dinocosta
marked this pull request as draft
August 6, 2026 21:45
Update `Operation::execute` to retun `Result<Option<Change>>` over
`Result<OperationOutcome>` with `OperationOutcome` being the following
enum:
```rust
enum OperationOutcome {
Changed(Change),
Cancelled(Operation),
}
```
Seeing as the `Operation` present in `Cancelled` was never used, so we
don't actually need to track it.
Update `project_panel::undo::Inner::trash` in order to also require confirmation to trash the file if undoing or redoing an operation will lead to a file being trashed by the user. In order to get the tests working we now need to simulate clicking one of the prompt's buttons, so `TestContext::answer` has been introduced and tests have been updated accordingly.
Contributor
dinocosta
marked this pull request as ready for review
August 10, 2026 09:30
Member
Author
|
/cherry-pick stable |
Member
Author
|
/cherry-pick preview |
zed-zippy Bot
added a commit
that referenced
this pull request
Aug 11, 2026
…(cherry-pick to preview) (#62482) Cherry-pick of #62294 to preview ---- # Objective Ensure that, when users undo project panel operations, we don't trash files with unsaved edits as that could lead to data loss, as outlined [here](#62243 (comment)). Closes #62243 ## Solution Update `UndoManager::trash` to require confirmation before moving files to the trash. For files with unsaved edits, users can save, discard, or cancel the operation while clean files receive a standard trash confirmation, same as shown when trashing a file through the Project Panel. This helps avoid the issue where, if an user undoes a file creation for a file that has unsaved edits and then quits Zed, the edits that were saved in memory, as well as the Project Panel history, will now be gone and there's no way to recover the data. Batch operations have also been updated to now show a single confirmation before making filesystem changes, preventing partial execution when cancelled and warning about unsaved edits. Lastly, the trash/delete prompt building has been refactored in order for the Project Panel and Undo Manager to share the same wording, file-list truncation, and unsaved-change warnings. ## Testing Tested both manually as well as added the following tests: * `project_panel::tests::undo::undo_create_cancel_trash` * `project_panel::tests::undo::undo_create_dirty_file` * `project_panel::tests::undo::cancel_partial_trash_batch` * `project_panel::tests::undo::batch_trash_warns_about_unsaved_changes` ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase The screen recording below shows the trash confirmation dialog on both a clean and dirty files, on both undo and redo flows. https://github.com/user-attachments/assets/0f9b96f5-0357-4e3f-8ec2-141486942c89 --- Release Notes: - Fixed issue with undoing or redoing project panel operations that could lead to a file with unsaved edits being trashed without confirmation. Co-authored-by: Dino <dinojoaocosta@gmail.com>
zed-zippy Bot
added a commit
that referenced
this pull request
Aug 12, 2026
…(cherry-pick to stable) (#62481) Cherry-pick of #62294 to stable ---- # Objective Ensure that, when users undo project panel operations, we don't trash files with unsaved edits as that could lead to data loss, as outlined [here](#62243 (comment)). Closes #62243 ## Solution Update `UndoManager::trash` to require confirmation before moving files to the trash. For files with unsaved edits, users can save, discard, or cancel the operation while clean files receive a standard trash confirmation, same as shown when trashing a file through the Project Panel. This helps avoid the issue where, if an user undoes a file creation for a file that has unsaved edits and then quits Zed, the edits that were saved in memory, as well as the Project Panel history, will now be gone and there's no way to recover the data. Batch operations have also been updated to now show a single confirmation before making filesystem changes, preventing partial execution when cancelled and warning about unsaved edits. Lastly, the trash/delete prompt building has been refactored in order for the Project Panel and Undo Manager to share the same wording, file-list truncation, and unsaved-change warnings. ## Testing Tested both manually as well as added the following tests: * `project_panel::tests::undo::undo_create_cancel_trash` * `project_panel::tests::undo::undo_create_dirty_file` * `project_panel::tests::undo::cancel_partial_trash_batch` * `project_panel::tests::undo::batch_trash_warns_about_unsaved_changes` ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase The screen recording below shows the trash confirmation dialog on both a clean and dirty files, on both undo and redo flows. https://github.com/user-attachments/assets/0f9b96f5-0357-4e3f-8ec2-141486942c89 --- Release Notes: - Fixed issue with undoing or redoing project panel operations that could lead to a file with unsaved edits being trashed without confirmation. Co-authored-by: Dino <dinojoaocosta@gmail.com>
playdohface
pushed a commit
to playdohface/zed
that referenced
this pull request
Aug 29, 2026
…stries#62294) # Objective Ensure that, when users undo project panel operations, we don't trash files with unsaved edits as that could lead to data loss, as outlined [here](zed-industries#62243 (comment)). Closes zed-industries#62243 ## Solution Update `UndoManager::trash` to require confirmation before moving files to the trash. For files with unsaved edits, users can save, discard, or cancel the operation while clean files receive a standard trash confirmation, same as shown when trashing a file through the Project Panel. This helps avoid the issue where, if an user undoes a file creation for a file that has unsaved edits and then quits Zed, the edits that were saved in memory, as well as the Project Panel history, will now be gone and there's no way to recover the data. Batch operations have also been updated to now show a single confirmation before making filesystem changes, preventing partial execution when cancelled and warning about unsaved edits. Lastly, the trash/delete prompt building has been refactored in order for the Project Panel and Undo Manager to share the same wording, file-list truncation, and unsaved-change warnings. ## Testing Tested both manually as well as added the following tests: * `project_panel::tests::undo::undo_create_cancel_trash` * `project_panel::tests::undo::undo_create_dirty_file` * `project_panel::tests::undo::cancel_partial_trash_batch` * `project_panel::tests::undo::batch_trash_warns_about_unsaved_changes` ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase The screen recording below shows the trash confirmation dialog on both a clean and dirty files, on both undo and redo flows. https://github.com/user-attachments/assets/0f9b96f5-0357-4e3f-8ec2-141486942c89 --- Release Notes: - Fixed issue with undoing or redoing project panel operations that could lead to a file with unsaved edits being trashed without confirmation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Ensure that, when users undo project panel operations, we don't trash files with unsaved edits as that could lead to data loss, as outlined here.
Closes #62243
Solution
Update
UndoManager::trashto require confirmation before moving files to the trash. For files with unsaved edits, users can save, discard, or cancel the operation while clean files receive a standard trash confirmation, same as shown when trashing a file through the Project Panel.This helps avoid the issue where, if an user undoes a file creation for a file that has unsaved edits and then quits Zed, the edits that were saved in memory, as well as the Project Panel history, will now be gone and there's no way to recover the data.
Batch operations have also been updated to now show a single confirmation before making filesystem changes, preventing partial execution when cancelled and warning about unsaved edits.
Lastly, the trash/delete prompt building has been refactored in order for the Project Panel and Undo Manager to share the same wording, file-list truncation, and unsaved-change warnings.
Testing
Tested both manually as well as added the following tests:
project_panel::tests::undo::undo_create_cancel_trashproject_panel::tests::undo::undo_create_dirty_fileproject_panel::tests::undo::cancel_partial_trash_batchproject_panel::tests::undo::batch_trash_warns_about_unsaved_changesSelf-Review Checklist:
Showcase
The screen recording below shows the trash confirmation dialog on both a clean and dirty files, on both undo and redo flows.
CleanShot.2026-08-10.at.10.24.45.mp4
Release Notes: