Skip to content

project_panel: Confirm before trashing unsaved file on undo - #62294

Merged
dinocosta merged 8 commits into
mainfrom
62243-project-panel-trash-fix
Aug 10, 2026
Merged

project_panel: Confirm before trashing unsaved file on undo#62294
dinocosta merged 8 commits into
mainfrom
62243-project-panel-trash-fix

Conversation

@dinocosta

@dinocosta dinocosta commented Aug 6, 2026

Copy link
Copy Markdown
Member

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::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:

  • 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 and icon guidelines)
  • Tests cover the new/changed behavior
  • 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.

CleanShot.2026-08-10.at.10.24.45.mp4

Release Notes:

  • Fixed issue with undoing or redoing project panel operations that could lead to a file with unsaved edits being trashed without confirmation.

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.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 6, 2026
@dinocosta dinocosta self-assigned this Aug 6, 2026
@dinocosta
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.
@zed-industries-bot

zed-industries-bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
Messages
📖

This PR includes links to the following GitHub Issues: #62243
If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by 🚫 dangerJS against 2539ba0

@dinocosta
dinocosta marked this pull request as ready for review August 10, 2026 09:30
@dinocosta dinocosta added the staff Pull requests authored by a current member of Zed staff label Aug 10, 2026

@smitbarmase smitbarmase left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it! 🚀

@dinocosta
dinocosta added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit d4010e9 Aug 10, 2026
49 checks passed
@dinocosta
dinocosta deleted the 62243-project-panel-trash-fix branch August 10, 2026 11:51
@dinocosta

Copy link
Copy Markdown
Member Author

/cherry-pick stable

@dinocosta

Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undo in the Code pane deletes files without prompting causing lost work

3 participants