Skip to content

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

test(ui): marquee shift+alt before the drag intersects the selection (#208) (#3624)

agent-34602255b330138464
diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rs
index a660a92dd..241f5aa04 100644
--- a/crates/ui-egui/src/marquee_tests.rs
+++ b/crates/ui-egui/src/marquee_tests.rs
@@ -383,6 +383,32 @@ fn modifiers_held_before_the_drag_pick_the_mode_not_the_shape() {
assert!(sel.sample_channel(120, 110, 0) < 0.01 && sel.sample_channel(90, 110, 0) > 0.99, "subtracted, not centred");
}
+/// #208: `⇧⌥` held at the press intersects, the third selection mode after add (`⇧`) and subtract
+/// (`⌥`). Like those, the modifier at the press picks the mode; here the keys are released once the
+/// press has fixed the mode, so the drag stays a plain rectangle and only the overlap of the
+/// existing selection and the dragged rectangle survives. The three sample points below are each in
+/// exactly one of {overlap, first-only, drag-only}, so they pass only for intersect, not for
+/// replace, add or subtract.
+#[test]
+fn shift_alt_before_the_drag_intersects_the_selection() {
+ let mut h = harness(Tool::RectMarquee);
+ // A: the existing selection, 50..200 on both axes.
+ h.state_mut().run("select.rect", json!({"x": 50, "y": 50, "width": 150, "height": 150})).unwrap();
+ let both = Modifiers::SHIFT | Modifiers::ALT;
+ mods(&mut h, both);
+ press_at(&mut h, 120.0, 120.0, both);
+ // Mode is fixed at the press; releasing the keys keeps intersect mode but leaves the drag a
+ // plain rectangle (no square/centre constraint), so B is roughly 120..300 on both axes.
+ mods(&mut h, Modifiers::NONE);
+ move_to(&mut h, 300.0, 300.0);
+ release_at(&mut h, 300.0, 300.0, Modifiers::NONE);
+ let st = h.state().session.active().unwrap();
+ let sel = st.doc.selection.as_ref().expect("a selection survives the intersect");
+ assert!(sel.sample_channel(160, 160, 0) > 0.99, "the overlap of the two rectangles stays selected");
+ assert!(sel.sample_channel(60, 60, 0) < 0.01, "a point only in the existing selection is dropped (not add)");
+ assert!(sel.sample_channel(260, 260, 0) < 0.01, "a point only in the dragged rectangle is dropped (not replace)");
+}
+
/// `cargo test --release -p photocraft-ui-egui marquee_drag_bench -- --ignored --nocapture`
#[test]
#[ignore]