From 19f06c9322aafd5c307ee9d98de4502d314f66b1 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 21:33:31 +0000 Subject: [PATCH] Transform session: Undo or Redo inside the nudge pause records the nudges as their own step first, so Redo finds nothing after them --- crates/draw/src/ui/transform/session.rs | 5 ++++- crates/draw/tests/it/transform_session.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/draw/src/ui/transform/session.rs b/crates/draw/src/ui/transform/session.rs index f97c822dc..2d0905a07 100644 --- a/crates/draw/src/ui/transform/session.rs +++ b/crates/draw/src/ui/transform/session.rs @@ -588,12 +588,15 @@ impl TransformSession { } } - /// Undo or redo one step; refused while a gesture runs. + /// Undo or redo one step; refused while a gesture runs. A change not yet at rest (a run of nudges inside the + /// nudge pause) becomes its own step first, so Undo takes it back and Redo finds nothing after it. fn step(&mut self, step: Step) -> bool { + // pc: crates/ui-egui/src/tools/transform_tool/commit.rs:441 (`step` settles before it pops). if self.dragging() { return false; } self.last_nudge = None; + self.record_rest(); let moved = self.history.step(&mut self.draft, step); self.rested = self.draft.clone(); self.changed = false; diff --git a/crates/draw/tests/it/transform_session.rs b/crates/draw/tests/it/transform_session.rs index 04826599e..75bb84c90 100644 --- a/crates/draw/tests/it/transform_session.rs +++ b/crates/draw/tests/it/transform_session.rs @@ -117,6 +117,22 @@ fn nudges_within_the_pause_fold_into_one_step() { assert_eq!(steps(&mut plain), 2); } +// Undo or Redo inside the nudge pause ends the run first: the nudges are a step of their own, which drops what was +// undone before them. +#[trial] +fn undo_or_redo_inside_the_nudge_pause_keeps_the_nudges_as_their_own_step() { + let at = |s: &TransformSession| s.quad()[0]; + let mut s = session().nudge_pause(Some(1.0)); + drag(&mut s, moved(doc(30.0, 0.0)), 0.0); + drag(&mut s, moved(doc(60.0, 0.0)), 0.1); + assert!(s.undo()); + nudge(&mut s, moved(doc(31.0, 0.0)), 0.2); + assert!(!s.redo(), "the nudge dropped the undone drag"); + assert!(near(at(&s), Point::new(31.0, 0.0)), "{:?}", at(&s)); + assert!(s.undo(), "the nudge is a step"); + assert!(near(at(&s), Point::new(30.0, 0.0)), "{:?}", at(&s)); +} + // Between a Box Begin and its Commit, undo and redo return false and change nothing. // `homography` maps the frame's corners onto the box's corners and its centre into the box; a box