Undo mutations after :w #35
Labels
No labels
autorelease: pending
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream/digest
upstream/pr
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
barrettruth/canola.nvim#35
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
After saving mutations with
:w(rename, delete, move, create), pressinguin the oil buffer reports "already at latest change". Neovim's undo tree tracks buffer text only — it has no knowledge of the filesystem operations that were performed. There is no way to reverse a confirmed mutation through the editor.Consolidates
Scope
The feature requested in both issues is the same: after confirming mutations, the user should be able to undo them — ideally with
uas they would any other edit, or at minimum via a dedicated action.The difficulty is that filesystem operations are not atomic and not uniformly reversible:
A mutation undo stack would need to record the inverse operation for each action at execution time and replay inverses in reverse order. Partial undo (rolling back only some operations in a batch) is especially hard when later operations depend on earlier ones (e.g., move A → B, then move B → C: undoing only the second step is valid, but undoing only the first is not).
Approach options
Option A — dedicated undo action: a
undo_last_mutationsaction that replays the inverse of the most recently confirmed batch. Does not integrate withu; user binds it explicitly. Simpler to implement and explain.Option B — hook into Neovim undo: after mutations complete, synthesize a buffer change that represents the inverse state (re-render the pre-mutation buffer text), so
unaturally reverts the buffer and the next:wre-applies the inverse operations. Clever but fragile — the undo entry would need to survive buffer re-renders triggered by the mutation itself.Option A is more realistic. Option B has too many edge cases with how oil re-renders the buffer after each
:w.Constraints
Complexity
High. Requires a parallel mutation log alongside Neovim's undo tree, inverse-operation computation for each action type, and careful interaction with the buffer re-render that follows every
:w.Closing — the confirmation dialog already prevents accidental mutations, and "just rename it back" covers the common case. A parallel undo stack adds significant complexity (inverse computation, batch ordering, partial failure handling) for marginal UX improvement. stevearc labeled this P1 upstream 3 years ago and never shipped it.