bug: undo merges two unrelated edits made within 350 ms #15

Closed
opened 2026-11-16 14:26:50 +00:00 by ben · 0 comments
Owner

Version: 0.1.2 (main @ 41c7fc5)
System: any.

Steps to reproduce

  1. Change contrast (drag the slider) and let go.
  2. Within a third of a second, change brightness.
  3. Press Ctrl+Z once.

What should have happened

One Ctrl+Z per edit: the brightness change is reverted, the contrast change stays.

What happened instead

Both edits come back with a single undo — verified through the real frame loop with two edits 28 ms apart: after one Ctrl+Z the parameters are back at the state from before the first edit. Two unrelated controls, two separate gestures, one undo step.

Where it is

The frame hook coalesces history by wall-clock time, not by gesture (main.rs:3099):

if self.doc_changed && !self.timeline.playing && !self.restoring {
    if now - self.history_pushed_at > 0.35 {
        self.push_history();
        self.history_pushed_at = now;

The 0.35 s window was added so one slider drag becomes one step, which is right. It also swallows any other edit that happens inside the window — and 0.35 s is a long time when the second edit is a click on a different control.

Suggested fix

Coalesce by identity rather than by time: remember what was edited (the control id, or the field) and how the pointer is doing (a drag is one step from press to release; a click is a step on its own). Then two different controls never merge, and one drag still never produces sixty steps. A simple version: a step is pushed when the edited control changes, or when the pointer is released, whichever comes first.

A check that would catch it

An --uitest row: two edits on two different controls a few frames apart, one Ctrl+Z, assert only the second is undone. The current behaviour fails it (verified with a throwaway probe: (100.0, 100.0) -> contrast 150, brightness 40 -> one undo -> (100.0, 100.0)).

Version: 0.1.2 (`main` @ 41c7fc5) System: any. ## Steps to reproduce 1. Change contrast (drag the slider) and let go. 2. Within a third of a second, change brightness. 3. Press `Ctrl+Z` once. ## What should have happened One `Ctrl+Z` per edit: the brightness change is reverted, the contrast change stays. ## What happened instead Both edits come back with a single undo — verified through the real frame loop with two edits 28 ms apart: after one `Ctrl+Z` the parameters are back at the state from before the *first* edit. Two unrelated controls, two separate gestures, one undo step. ## Where it is The frame hook coalesces history by wall-clock time, not by gesture (`main.rs:3099`): ```rust if self.doc_changed && !self.timeline.playing && !self.restoring { if now - self.history_pushed_at > 0.35 { self.push_history(); self.history_pushed_at = now; ``` The 0.35 s window was added so one slider drag becomes one step, which is right. It also swallows any *other* edit that happens inside the window — and 0.35 s is a long time when the second edit is a click on a different control. ## Suggested fix Coalesce by identity rather than by time: remember *what* was edited (the control id, or the field) and how the pointer is doing (a drag is one step from press to release; a click is a step on its own). Then two different controls never merge, and one drag still never produces sixty steps. A simple version: a step is pushed when the edited control changes, or when the pointer is released, whichever comes first. ## A check that would catch it An `--uitest` row: two edits on two different controls a few frames apart, one `Ctrl+Z`, assert only the second is undone. The current behaviour fails it (verified with a throwaway probe: `(100.0, 100.0) -> contrast 150, brightness 40 -> one undo -> (100.0, 100.0)`).
ben closed this issue 2026-11-16 19:40:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ben/openDither#15
No description provided.