Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Lasso: an open Free Transform box takes the drag with the Lasso selected (#2153) (#2766)

Valentin Kleinf9700ea95e32
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index e005dd280..cd112da0a 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -2627,7 +2627,9 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
Tool::PolygonLasso => polygon_retract(app),
_ => false,
};
- if tool == Tool::Lasso {
+ // The Lasso reads its own presses and drops the moves of a drag it didn't start, so an
+ // open Free Transform box takes the usual drag path instead (#2153).
+ if tool == Tool::Lasso && !transform_owns_pointer {
crate::lasso_ui::canvas_input(app, &ctx, &xf, &response);
(buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false);
}
diff --git a/crates/ui-egui/src/transform_undo_tests.rs b/crates/ui-egui/src/transform_undo_tests.rs
index 9b8bcbbd8..56dca1482 100644
--- a/crates/ui-egui/src/transform_undo_tests.rs
+++ b/crates/ui-egui/src/transform_undo_tests.rs
@@ -227,6 +227,24 @@ fn the_hand_tool_does_not_steal_a_free_transform_drag() {
assert!(width(&h) > 150, "the committed resize applied: {}", width(&h));
}
+/// With the (freehand) Lasso selected, a Free Transform of a lasso selection follows the drag: the
+/// Lasso reads its own pointer events, and dropped the moves and release of a drag it hadn't
+/// started, so the box never changed (#2153).
+#[test]
+fn the_lasso_tool_does_not_swallow_a_free_transform_drag() {
+ let mut h = harness_tool(Tool::Lasso);
+ let outline = json!([[90, 90], [210, 90], [210, 170], [90, 170]]);
+ h.state_mut().run("select.lasso", json!({"points": outline})).unwrap();
+ begin(&mut h);
+ let q0 = quad(&h);
+ drag(&mut h, q0[2], [300.0, 220.0]);
+ let q1 = quad(&h);
+ assert!(!close(q1, q0), "the drag scaled the box: {q1:?}");
+ key(&mut h, Modifiers::NONE, Key::Enter);
+ assert!(h.state().ui.transform.is_none(), "the transform committed");
+ assert!(width(&h) > 150, "the committed resize applied: {}", width(&h));
+}
+
/// Holding Space (the temporary Hand, #249) still pans the view while a Free Transform box is open,
/// rather than resizing it (#2302 review): only the selected Hand yields to the box.
#[test]