Transform session: Undo or Redo inside the nudge pause records the nudges as their own step first, so Redo finds nothing after them

This commit is contained in:
aiongg
2026-11-16 21:33:31 +00:00
parent 1231eaa6ff
commit 19f06c9322
2 changed files with 20 additions and 1 deletions
+4 -1
View File
@@ -588,12 +588,15 @@ impl<W: TransformWarp> TransformSession<W> {
}
}
/// 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;
+16
View File
@@ -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<Warp>| 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