Skip to content

refactor(core): undo and redo take the editors' own answer, with no body special case - #6

Merged
adammharris merged 1 commit into
mainfrom
agent/backlog-can-undo-counts-edits-not-steps
Oct 26, 2026
Merged

adammharris merged 1 commit into
mainfrom
agent/backlog-can-undo-counts-edits-not-steps

Conversation

@adammharris

Copy link
Copy Markdown
Member

What changed

DocumentSession::undo and redo (crates/provui-core/src/session.rs) now use the bool that leaf_core::Doc::undo/redo and flower_core::Model::undo/redo return. They used to snapshot both change counters around the call and compare them. The nothing_happened helper is gone, and with it the body-only "walk on when the body did not move" arm. A step that is pressed and does not move now stops the walk in either editor, and its journal entry stays where it was. The metadata side already worked this way.

Exhaustion skipping stays as it was. Body entries left over after a coalesced run are passed over before they are pressed, because leaf's can_undo is exact.

Two smaller changes in the same file: a leftover debug eprintln! is removed from a_coalesced_run_of_typing_does_not_cost_a_keypress_per_character, and counters() is folded into mark_seen, its only remaining caller.

Why

This is provui's half of leaf's task can-undo-counts-edits-not-steps. Its done-when says provui's DocumentSession can drop the "walk on when the body did not move" special case. That case existed because leaf's can_undo counted edits rather than twig's steps. leaf has fixed that, and provui's lock (leaf 712f12e) already includes the fix.

Behavioural change: if leaf refuses a body undo or redo after reporting a step to take (twig failing), the walk now stops and keeps its entry. Before, it dropped the entry and carried on to older entries, so a metadata edit could be undone in answer to a body step that failed.

Task

This closes the remaining half of leaf docs/tasks/can-undo-counts-edits-not-steps.md. The task file lives in leaf, so it cannot be closed on this branch. It should be moved to closed/ in leaf once this PR is merged.

Verification

  • ship ci passed locally: fmt, clippy -D warnings, tests, docs, package isolation and MSRV.
  • New test: undo_says_whether_it_moved_and_can_undo_ends_with_the_body. Five characters are typed, then undone until the body stops moving. Each undo()'s answer must match whether the body's revision moved, and at the end can_undo() must be false and redo must work.
  • This test passes on main too. The arm removed here was unreachable with an exact can_undo, so no test can fail before the change. The existing undo tests in core and the TUI also pass unchanged.

…ody special case

leaf's `can_undo` now mirrors twig's stacks exactly and `Doc::undo` /
`Doc::redo` return whether they moved, so a body entry is only pressed when
leaf has a step to take. `DocumentSession::undo` and `redo` read the verbs'
`bool` instead of snapshotting both change counters around the call, and drop
the "walk on when the body did not move" arm: a pressed step that does not
move is a refusal in either editor, and keeps its entry.

Closes leaf's task can-undo-counts-edits-not-steps (its provui half).

Behavioural-change: a body undo or redo that leaf refuses after reporting a step to take (twig failing) now stops the walk and leaves its journal entry in place, where it used to drop the entry and go on to the next one.
@adammharris
adammharris merged commit ce1db7a into main Oct 26, 2026
7 checks passed
@adammharris
adammharris deleted the agent/backlog-can-undo-counts-edits-not-steps branch October 30, 2026 01:26
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