diff --git a/crates/ui-egui/src/move_shift_click_tests.rs b/crates/ui-egui/src/move_shift_click_tests.rs index b197cf1c00..687ad24ec0 100644 --- a/crates/ui-egui/src/move_shift_click_tests.rs +++ b/crates/ui-egui/src/move_shift_click_tests.rs @@ -105,6 +105,46 @@ fn point_clicks_toggle_members_but_keep_the_singleton_and_plain_multi_selection( assert_eq!(f.bounds(), before, "selection-only gestures move no pixels"); } +#[test] +fn group_auto_select_picks_and_moves_the_enclosing_group() { + let mut f = Fixture::new(); + let [a, b, _] = f.layers; + f.select(&[a]); + let group = LayerId(f.app.run("layer.new.groupFromLayers", json!({"name": "G"})).unwrap()["layer"].as_u64().unwrap()); + f.select(&[b]); + f.app.ui.tool_options.move_target = "group".into(); + let before = f.bounds(); + f.gesture([14.0, 14.0], [20.0, 16.0], Modifiers::NONE); + f.assert_selected(&[group]); + assert_eq!(f.bounds()[1], before[1].translate(6, 2), "the group moves its child"); + assert_eq!(f.bounds()[2], before[2], "the other layer stays put"); +} + +#[test] +fn dragging_a_selected_layer_moves_the_whole_selection() { + let mut f = Fixture::new(); + let [a, b, _] = f.layers; + f.select(&[a, b]); + let before = f.bounds(); + f.gesture([14.0, 14.0], [20.0, 16.0], Modifiers::NONE); + f.assert_selected(&[a, b]); + assert_eq!(f.bounds()[1], before[1].translate(6, 2)); + assert_eq!(f.bounds()[2], before[2].translate(6, 2)); +} + +#[test] +fn shift_click_adds_shape_layers_one_after_another() { + let mut f = Fixture::new(); + let ids = [10, 34, 58].map(|x| { + let layer = f.app.run("shape.create", json!({"kind": "rect", "rect": [x, 35, 10, 10], "fill": "#ff0000"})).unwrap(); + LayerId(layer["layer"].as_u64().unwrap()) + }); + f.gesture([15.0, 40.0], [15.0, 40.0], Modifiers::NONE); + f.gesture([39.0, 40.0], [39.0, 40.0], Modifiers::SHIFT); + f.gesture([63.0, 40.0], [63.0, 40.0], Modifiers::SHIFT); + f.assert_selected(&ids); +} + /// Shift-press changes the selected set immediately, and only that set moves on drag (#11102). #[test] fn shift_drag_moves_the_layers_selected_after_the_press() { diff --git a/crates/ui-egui/src/transform_commit_click_tests.rs b/crates/ui-egui/src/transform_commit_click_tests.rs index df7eb33857..cfd4253c6d 100644 --- a/crates/ui-egui/src/transform_commit_click_tests.rs +++ b/crates/ui-egui/src/transform_commit_click_tests.rs @@ -89,8 +89,12 @@ fn a_click_on_another_layers_pixels_commits_and_keeps_the_selection() { app.ui.extras.rulers = false; app.ui.extras.snap = false; // "Other" has a blue block at x 120..160, y 120..160; "Paint" a red one at x 20..60, y 20..60. + let mut other = None; for (name, at, color) in [("Other", 120, "#0000ff"), ("Paint", 20, "#ff0000")] { let id = app.run("layer.new.layer", json!({"name": name})).unwrap()["layer"].as_u64().unwrap(); + if name == "Other" { + other = Some(LayerId(id)); + } app.run("layer.select", json!({"layer": id})).unwrap(); app.run("select.rect", json!({"x": at, "y": at, "width": 40, "height": 40})).unwrap(); app.run("edit.fill", json!({"contents": "color", "color": color})).unwrap(); @@ -99,13 +103,20 @@ fn a_click_on_another_layers_pixels_commits_and_keeps_the_selection() { let paint = app.session.active().unwrap().active_layer.unwrap(); let app_ctx = app.ctx().clone(); crate::menus::invoke(&mut app, &app_ctx, "edit.freeTransform", json!({})).unwrap(); - shift_right(&mut app); + app.ui.transform.as_mut().unwrap().edit_box(|b| *b = b.scaled_about_pivot(2.0, 2.0)); let before = steps(&app); click(&mut app, [140.0, 140.0]); assert!(app.ui.transform.is_none(), "committed"); assert_eq!(steps(&app), before + 1); + let bounds = app.session.active().unwrap().doc.layer(paint).unwrap().surface().unwrap().content_bounds(); + assert_eq!(bounds, photocraft_geom::Rect::new(0, 0, 80, 80), "the resized pixels are committed"); assert_eq!(app.session.active().unwrap().history.entries().last().map(ToString::to_string).as_deref(), Some("Free Transform")); assert_eq!(app.session.active().unwrap().selected_layers(), vec![paint], "the selection doesn't change"); + app.ui.tool = crate::state::Tool::Move; + app.ui.tool_options.move_auto_select = true; + app.ui.tool_options.move_target = "layer".into(); + click(&mut app, [140.0, 140.0]); + assert_eq!(app.session.active().unwrap().selected_layers(), vec![other.unwrap()], "the second click picks the other layer"); } /// A layer linked to the transformed one after the box opened moves with the commit