fix(undo): a step is bounded by the gesture, not by 350 ms #23

Merged
ben merged 1 commit from fix/undo-gestures into main 2026-11-16 19:40:33 +00:00
Owner

Fixes #15.

The frame hook folded history by wall-clock time, which was meant to make one
slider drag one step and instead swallowed any other control edited inside the
window: drag contrast, let go, drag brightness within a third of a second, and one
Ctrl+Z took both back.

A step is bounded by the gesture that made it now:

  • a change that arrives with the pointer in use is a step that is pushed when the
    pointer comes up — the release itself ends it, so the next drag cannot join in,
    and however long the drag took it stays one step;
  • a second widget taking over the keyboard splits the step even without a click.
    The split happens at the document as it stood at the end of the previous frame,
    so a control whose change arrives in the same frame as the hand-over still gets
    a step of its own. One split per frame is the contract: two more controls in
    that same frame share the step they land in;
  • the 350 ms window stays as the fallback for changes without a gesture (a typed
    number, a menu command), and never fires in the middle of one.

The checkpoint the split uses is only trusted while a change is actually pending
(a flag the hook sets, not an inferred comparison), and it is guarded by
Snapshot::same_as, so an edit that changed nothing records nothing. A load, a
preset and a new document settle the document they install as the place undo
starts from.

Four more halves of the same bug came out of the checks: a press on a slider that
does not move, Clear (two steps, the first one undoing to nothing), an edit made
while the animation plays (never recorded at all), and opening a project
(recorded a step against the reset state and marked the document unsaved).

Checks

  • cargo test --release: 256 passed (4 new: changes-nothing, same-frame
    hand-over, load leaving no checkpoint, and a project load not recording a step —
    each verified to fail without its fix)
  • --audit: 558 checks, 558 passed, 1 skipped
  • --controls: 62 checked, 0 failed
  • --uitest: 111 checks, 111 passed (6 new: two drags, a 450 ms drag, Clear,
    undo during playback, animation frames not being steps, and a typed edit
    followed by a drag)
  • --selftest: 456 renders, 0 failures
  • cargo fmt --check: clean
  • Reviewer: five rounds, four rounds of real findings (focus hand-over, playback,
    Clear, stale checkpoints, project load); the sixth round found nothing and
    approved the merge
Fixes #15. The frame hook folded history by wall-clock time, which was meant to make one slider drag one step and instead swallowed any *other* control edited inside the window: drag contrast, let go, drag brightness within a third of a second, and one `Ctrl+Z` took both back. A step is bounded by the gesture that made it now: - a change that arrives with the pointer in use is a step that is pushed when the pointer comes up — the release itself ends it, so the next drag cannot join in, and however long the drag took it stays one step; - a second widget taking over the keyboard splits the step even without a click. The split happens at the document as it stood at the end of the previous frame, so a control whose change arrives in the same frame as the hand-over still gets a step of its own. One split per frame is the contract: two more controls in that same frame share the step they land in; - the 350 ms window stays as the fallback for changes without a gesture (a typed number, a menu command), and never fires in the middle of one. The checkpoint the split uses is only trusted while a change is actually pending (a flag the hook sets, not an inferred comparison), and it is guarded by `Snapshot::same_as`, so an edit that changed nothing records nothing. A load, a preset and a new document settle the document they install as the place undo starts from. Four more halves of the same bug came out of the checks: a press on a slider that does not move, `Clear` (two steps, the first one undoing to nothing), an edit made while the animation plays (never recorded at all), and opening a project (recorded a step against the reset state and marked the document unsaved). ### Checks - `cargo test --release`: 256 passed (4 new: changes-nothing, same-frame hand-over, load leaving no checkpoint, and a project load not recording a step — each verified to fail without its fix) - `--audit`: 558 checks, 558 passed, 1 skipped - `--controls`: 62 checked, 0 failed - `--uitest`: 111 checks, 111 passed (6 new: two drags, a 450 ms drag, Clear, undo during playback, animation frames not being steps, and a typed edit followed by a drag) - `--selftest`: 456 renders, 0 failures - `cargo fmt --check`: clean - Reviewer: five rounds, four rounds of real findings (focus hand-over, playback, Clear, stale checkpoints, project load); the sixth round found nothing and approved the merge
The frame hook folded history by wall-clock time, which was meant to make one
slider drag one step and instead swallowed any *other* control edited inside the
window: drag contrast, let go, drag brightness within a third of a second, and one
`Ctrl+Z` took both back (issue #15).

A step is bounded by the gesture that made it now:

- a change that arrives with the pointer in use is a step that is pushed when the
  pointer comes up — the release itself ends it, so the next drag cannot join in,
  and however long the drag took it stays one step;
- a second widget taking over the keyboard splits the step even without a click.
  The split happens at the document as it stood at the end of the previous frame,
  so a control whose change arrives in the same frame as the hand-over still gets
  a step of its own. One split per frame is the contract: two more controls in
  that same frame share the step they land in, which is as fine-grained as a
  frame can tell them apart;
- the 350 ms window stays as the fallback for changes without a gesture (a typed
  number, a menu command), and never fires in the middle of one.

The checkpoint the split uses is only trusted while a change is actually pending
(a flag the hook sets, not an inferred comparison). A load, a preset and a new
document settle the document they install as the place undo starts from, so none
of them can leave a stale checkpoint — or a step against the reset state it was
applied to — behind.

The new checks found three more halves of the same bug:

- a press on a slider that does not move, or a re-render of an unchanged
  document, recorded a step that undid to itself, and that empty step pushed the
  real one out of reach. `Snapshot::same_as` answers "same document" by comparing
  the state and the pictures' `Arc`s by identity, so such a frame records
  nothing. `push_history` itself still records unconditionally, for callers that
  mean "this state is a step".
- `Clear` pushed a step of its own *and* let the frame hook push one, so the first
  undo did nothing. It records nothing itself now; the hook knows what the state
  before it was.
- an edit made while the animation plays was never recorded (`!timeline.playing`
  in the hook and in `undo`), so `Ctrl+Z` said "Nothing to undo". A frame of the
  animation is the same document — `same_as` sees that — so the guard could go.
- opening a project recorded a step against the reset state and marked the
  document unsaved, because the render a load ends with looks like an edit.

Checks: `--uitest` rows "two drags a few frames apart are two undo steps" (with
the wall-clock window it reports contrast 100 -> 140, brightness 100 -> 60, and
one undo takes both back), "a slow drag is still one undo step" (a 450 ms drag
used to become two), "Clear records one step, and one undo brings it back",
"Ctrl+Z undoes an edit made while the animation plays", "a frame of the animation
is not an undo step" (30 frames of playback, stack exactly unchanged) and "a typed
edit and a drag are two steps, in the right order"; plus four unit tests — the
changes-nothing case, the same-frame hand-over (fails when the split is a no-op),
a load not leaving a checkpoint behind, and opening a project recording no step
and undoing to the loaded document (both fail without their fix).

Fixes #15.

Checks: cargo test 256 (4 new), --audit 558, --controls 62, --uitest 111 (6 new),
--selftest 456, fmt clean.
ben merged commit 3e793b96ef into main 2026-11-16 19:40:33 +00:00
Sign in to join this conversation.
No description provided.