Skip to content

Undo and Redo (⌘Z, ⇧⌘Z) for Trash, rename and new items - #4

Closed
LennZone wants to merge 2 commits into
web-workers-com:mainfrom
LennZone:undo
Closed

LennZone wants to merge 2 commits into
web-workers-com:mainfrom
LennZone:undo

Conversation

@LennZone

@LennZone LennZone commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Items moved to the Trash couldn't be brought back with ⌘Z; Manta had no Undo for file operations at all (only Batch Rename had its own). This adds Undo (⌘Z) and Redo (⇧⌘Z), like Finder, in the Edit menu and the command palette:

What you did What ⌘Z does
Move to Trash (⌘⌫, dropping onto the sidebar Trash) Puts the items back where they were
Rename (dialog, in place, Info window) Brings back the old name, on servers too
New Folder / New File on the Mac Moves the new item to the Trash (like Finder); Redo puts it back
New Folder / New File on a server, S3 or container Deletes it, only while it is still empty

Details:

  • New module crates/app/src/undo.rs: each history entry is the operation that reverts one step; running it yields the operation that reverts that, which goes on the other stack. Session only, 100 steps per stack, a new operation clears Redo. Steps run on the worker one at a time.
  • Nothing is ever replaced: if the original place is taken, Manta reports "Couldn't put back “name”" and keeps the step, so ⌘Z works again once the place is free.
  • Trasher::put_back moves items out of the Trash. Without Full Disk Access (macOS keeps apps out of ~/.Trash), it asks Finder, as Empty Trash already does; the paths are passed as osascript arguments, never into the script text.
  • Text fields (filter, path, rename) and a focused terminal panel keep ⌘Z / ⇧⌘Z.
  • A case-only rename (README.md → readme.md) is undone correctly on case-insensitive disks.
  • Not covered yet: copying and moving. Their undo needs per-item results (final names after "Keep Both", overwritten files) from crates/ops, which would extend its public API, so I'd like to discuss that separately first.

How to test

In a test folder, with cargo run -p manta:

  1. Select two items, ⌘⌫, then ⌘Z: both are back. ⇧⌘Z trashes them again.
  2. Rename a file (F2), ⌘Z: old name back. Also try a change of case only.
  3. ⇧⌘N a folder, ⌘Z: it's in the Trash; ⇧⌘Z brings it back.
  4. Trash notiz.txt, create a new notiz.txt outside Manta (echo new > notiz.txt), ⌘Z: error, new file untouched. Delete it, ⌘Z: the original is back.
  5. ⌘F, type something, ⌘Z: only the text changes.

New tests: crates/app/src/undo_ux_tests.rs (UI tests with the fake Trash) and unit tests in undo.rs. Not tested automatically: the real ~/.Trash and the Finder fallback (checked by hand with Full Disk Access only).

Checklist

  • cargo fmt --all --check passes
  • cargo clippy --workspace --all-targets -- -D warnings reports no warnings
  • scripts/test.sh passes (and scripts/test.sh full if backends, transfers or the terminal changed)
  • Tests added or updated for the change
  • New or changed UI strings are in the catalogs in all 7 languages (en, de, zh-Hans, es, fr, it, ru) and python3 scripts/i18n/check.py reports 0 problems
  • The glossary is regenerated if short UI terms changed (MANTA_UPDATE_GLOSSARY=1 cargo test -p manta glossary)
  • The user manual (docs/manual/, all 7 languages) and developer docs are updated, or no update is needed
  • docs/third-party-licenses.md is regenerated if dependencies changed (scripts/third-party-licenses.py) (no dependency changes)
  • I agree that my contribution is licensed under the MIT licence

⌘Z reverts the last file operation and ⇧⌘Z does it again, like Finder:
items moved to the Trash are put back where they were, a rename gets its
old name back (on servers too), and a new folder or file goes to the
Trash (on servers: deleted while still empty). Undo and Redo are in the
Edit menu and the command palette; text fields and the terminal keep ⌘Z.

Nothing is ever replaced: when the original place is taken, the step
stays and can be tried again. Without Full Disk Access, Finder puts
items back from the Trash. Copies and moves aren't recorded yet.
@LennZone

Copy link
Copy Markdown
Contributor Author

Closing in favour of #5, as discussed. The implementation stays on the branch in my fork in case it's useful.

@LennZone LennZone closed this Oct 30, 2026
@LennZone
LennZone deleted the undo branch November 3, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant