From efa62efa0c796a152d71d97af1f021a0a13067f0 Mon Sep 17 00:00:00 2001 From: Nigel Ihza Firdausy <106657905+Ni-zav@users.noreply.github.com> Date: Fri, 9 Oct 2026 20:11:07 +0700 Subject: [PATCH] Liquify: test that Alt-reversed strokes survive replay, undo and redo (#1675) Follow-up to #1494: Alt captured at stroke-down records the reversed tool, a later stroke records the selected one, and the field rebuilt from the strokes matches after undo and redo. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/liquify_ui.rs | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/ui-egui/src/liquify_ui.rs b/crates/ui-egui/src/liquify_ui.rs index 02505763db..33f31a4fac 100644 --- a/crates/ui-egui/src/liquify_ui.rs +++ b/crates/ui-egui/src/liquify_ui.rs @@ -935,6 +935,50 @@ mod tests { assert!(open(&mut app, &ctx).is_ok()); } + /// Follow-up to #1494 / #1484: Alt is captured at stroke-down and stays recorded + /// through undo, redo and deterministic Liquify field reconstruction. + #[test] + fn alt_reversed_twirl_survives_replay_undo_and_redo() { + let ctx = egui::Context::default(); + let mut app = app_with_layer(); + open(&mut app, &ctx).unwrap(); + control(&mut app, &json!({"tool": "twirlCw", "size": 36, "rate": 80})).unwrap(); + + // Releasing Alt while dragging must not change the tool recorded at pointer-down. + pointer(&mut app, ToolEvent::Down { x: 53.0, y: 40.0, pressure: 1.0 }, egui::Modifiers::ALT); + pointer(&mut app, ToolEvent::Move { x: 58.0, y: 41.0, pressure: 1.0 }, egui::Modifiers::NONE); + pointer(&mut app, ToolEvent::Up { x: 58.0, y: 41.0 }, egui::Modifiers::NONE); + let d = app.distort.liquify.as_ref().unwrap(); + assert_eq!(d.opts.tool, LiquifyTool::TwirlCw, "Alt must not change the selected tool"); + assert_eq!(d.strokes.len(), 1); + assert_eq!(d.strokes[0].tool, LiquifyTool::TwirlCcw); + assert_eq!(LiquifyField::from_strokes(d.canvas, d.cell, &d.strokes), d.field); + + // A following stroke without Alt records the original tool. + pointer(&mut app, ToolEvent::Down { x: 70.0, y: 40.0, pressure: 1.0 }, egui::Modifiers::NONE); + pointer(&mut app, ToolEvent::Move { x: 75.0, y: 42.0, pressure: 1.0 }, egui::Modifiers::ALT); + pointer(&mut app, ToolEvent::Up { x: 75.0, y: 42.0 }, egui::Modifiers::ALT); + let d = app.distort.liquify.as_ref().unwrap(); + assert_eq!(d.strokes.len(), 2); + assert_eq!(d.strokes[1].tool, LiquifyTool::TwirlCw); + assert_eq!(LiquifyField::from_strokes(d.canvas, d.cell, &d.strokes), d.field); + + control(&mut app, &json!({"undo": true})).unwrap(); + let d = app.distort.liquify.as_ref().unwrap(); + assert_eq!(d.strokes.len(), 1); + assert_eq!(d.strokes[0].tool, LiquifyTool::TwirlCcw); + assert_eq!(d.redo[0].tool, LiquifyTool::TwirlCw); + assert_eq!(LiquifyField::from_strokes(d.canvas, d.cell, &d.strokes), d.field); + + control(&mut app, &json!({"redo": true})).unwrap(); + let d = app.distort.liquify.as_ref().unwrap(); + assert_eq!(d.strokes.len(), 2); + assert!(d.redo.is_empty()); + assert_eq!(d.strokes[0].tool, LiquifyTool::TwirlCcw); + assert_eq!(d.strokes[1].tool, LiquifyTool::TwirlCw); + assert_eq!(LiquifyField::from_strokes(d.canvas, d.cell, &d.strokes), d.field); + } + #[test] fn dialog_strokes_match_the_engine_and_commit_once() { let ctx = egui::Context::default();