# Objective When an user uses the Project Panel to rename a file, it is possible to change its path too. For example, renaming `README.md` to `documents/README.md` will create the `documents/` directory, in case it doesn't yet exist. Unfortunately, even though undoing a rename operation is already supported, we were not yet considering this scenario where directories had been created specifically to support the rename. As such, when undo was used, for the scenario above, we'd end up moving `README.md` back to its original location but would leave the empty `documents/` directory behind. ## Solution Introduce two new operations and changes specifically for this use-case, `Operation::CreateDir`, `Operation::RemoveDir`, `Change::DirCreated` and `Change::DirRemoved`, which we can then batch together with the `Operation::Rename` in case directories need to be created or removed. An initial approach of just keeping the list of created directories in the `Operation::Rename` and `Change::Renamed` variants was considered but it would require all users of `Operation::Rename` to now set it, even if they don't actually need it, like the drag and paste operations. Having separate operations and change variants also makes it clearer what these are meant to be used for. Something else worth noting is that, for `Operation::CreateDir`, the directory will only be created if it doesn't yet exist, otherwise we'll ignore. Same happens for `Operation::RemoveDir`, where if the directory is not empty, we don't delete it, as it's possible for new files to have been added to the directory outside of Zed and we don't want to delete those. ## Testing Tested both manually as well as introduced a new test case – `project_panel::tests::undo::rename_with_dir_undo_redo` . ## 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 > This section is optional. If this PR does not include a visual change or does not add a new user-facing feature, you can delete this section. - Help others understand the result of this PR by showcasing your awesome work! - If this PR includes a visual change, consider adding a screenshot, GIF, or video - A before/after comparison is very useful for changes to existing features! While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases: <details> <summary>Before</summary> https://github.com/user-attachments/assets/15384fa8-9b94-495c-8992-19eee7a8f038 </details> <details> <summary>After</summary> https://github.com/user-attachments/assets/c5be9f38-a2b4-4acc-8a1e-178161e326bb </details> --- Release Notes: - Fixed undoing a file rename leaving behind directories created by the rename.
Zed
Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Installation
On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).
Other platforms are not yet available:
- Web (tracking discussion)
Developing Zed
Contributing
See CONTRIBUTING.md for ways you can contribute to Zed.
Also... we're hiring! Check out our jobs page for open roles.
Licensing
Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.
License information for third party dependencies must be correctly provided for CI to pass.
We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:
- Is it showing a
no license specifiederror for a crate you've created? If so, addpublish = falseunder[package]in your crate's Cargo.toml. - Is the error
failed to satisfy license requirementsfor a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to theacceptedarray inscript/licenses/zed-licenses.toml. - Is
cargo-aboutunable to find the license for a dependency? If so, add a clarification field at the end ofscript/licenses/zed-licenses.toml, as specified in the cargo-about book.
Sponsorship
Zed is developed by Zed Industries, Inc., a for-profit company.
If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.