diff --git a/crates/engine/src/tests/eyedropper.rs b/crates/engine/src/tests/eyedropper.rs index 445852f359..182d989662 100644 --- a/crates/engine/src/tests/eyedropper.rs +++ b/crates/engine/src/tests/eyedropper.rs @@ -698,6 +698,58 @@ fn picked_mesh_points_take_the_eyedropper_sample() { assert_ne!(node(&s, m).appearance, appearance); } +/// A Cmd-click with the Direct Selection tool the Eyedropper lends picks gradient mesh points for +/// the Eyedropper: the lent tool starts from the Eyedropper's picks, so a Shift-click adds to +/// them, and the Eyedropper samples into what the lent tool left picked (#8090). +#[test] +fn mesh_points_picked_through_the_lent_tool_take_the_eyedropper_sample() { + let mut s = session(); + // Two pixels, orange and teal, 100 pt each, at (300, 0). + let rgba = [[255u8, 128, 0, 255], [0, 128, 128, 255]].concat(); + let img = craft_image_codecs::Image::from_raw(2, 1, craft_image_codecs::ChannelLayout::Rgba, craft_image_codecs::SampleType::U8, rgba).unwrap(); + let png = craft_image_codecs::encode(&img, craft_image_codecs::Format::Png, &craft_image_codecs::EncodeOptions::default()).unwrap(); + s.edit("Place", |d, _| { + d.images.insert("px".into(), ImageBlob::png(png.to_vec())); + let l = d.layers[0].id; + let id = d.alloc_id(); + let xf = vectorcraft_geom::Affine::translate((300.0, 0.0)) * vectorcraft_geom::Affine::scale(100.0); + let im = ImageObject { key: "px".into(), width: 2, height: 1, xf, link: None, placement: Default::default(), pixels: None }; + d.insert(Some(l), 0, Node::new(id, NodeKind::Image(Box::new(im)))).map_err(|e| crate::EngineError::Other(e.to_string())) + }) + .unwrap(); + let m = rect(&mut s, 10.0); + s.execute("object.mesh.create", &json!({"ids": [m.0], "rows": 1, "cols": 1})).unwrap(); + let colors = |s: &Session| match node(s, m).kind { + NodeKind::Mesh(g) => g.points.iter().map(|p| p.color).collect::>(), + k => panic!("not a mesh: {k:?}"), + }; + let white = colors(&s)[0]; + let v = ViewInfo::default(); + let press = |s: &mut Session, i: usize, mods: Mods| { + let q = match node(s, m).kind { + NodeKind::Mesh(g) => g.points[i].p, + k => panic!("not a mesh: {k:?}"), + }; + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, q.x, q.y).with_mods(mods), v).unwrap(); + } + }; + let (teal, orange) = (Color::rgb8(0, 128, 128), Color::rgb8(255, 128, 0)); + s.execute("select.set", &json!({"ids": [m.0]})).unwrap(); + s.select_tool("directSelection", v).unwrap(); + press(&mut s, 0, Mods::default()); + s.select_tool("eyedropper", v).unwrap(); + // Cmd-click point 3: Direct Selection, lent, picks it in place of point 0. + press(&mut s, 3, Mods { cmd: true, ..Default::default() }); + assert_eq!(s.tool_id(), "eyedropper"); + click(&mut s, 450.0, 50.0, Mods::default()); + assert_eq!(colors(&s), [white, white, white, teal], "the point the lent tool picked takes the sample"); + // Cmd+Shift-click point 0 adds it to the Eyedropper's pick. + press(&mut s, 0, Mods { cmd: true, shift: true, ..Default::default() }); + click(&mut s, 350.0, 50.0, Mods::default()); + assert_eq!(colors(&s), [orange, white, white, orange], "both picked points take the sample"); +} + /// A CMYK document with one image of `px` (one row, 100 pt a pixel) at (300, 0). fn cmyk_doc_with_image(px: &[[u8; 4]]) -> Session { let mut s = Session::new(); diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 507cca86b4..8b8cf4628b 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -267,7 +267,13 @@ impl Session { // The lending tool does not see the press: it counts as a press elsewhere for the clicks a // double-click or triple-click compares. self.tool.press_elsewhere(); - let lent = self.make_tool(id); + let mut lent = self.make_tool(id); + // The gradient mesh points the Eyedropper holds are the lent tool's picks, which a Shift + // click adds to (#8090). + if self.tool.id() == "eyedropper" { + let points = self.tool.options().get("meshPoints").cloned().unwrap_or_else(|| Value::Array(vec![])); + lent.set_option("meshPoints", &points); + } self.selection_at_lend = self.active().map(|d| (d.uid, d.selection.clone())); self.lender = Some(std::mem::replace(&mut self.tool, lent)); Ok((PointerEvent { mods: Mods { cmd: false, ..ev.mods }, ..*ev }, settled)) @@ -278,10 +284,17 @@ impl Session { /// Cmd+click that takes the type being edited out of the selection ends its edit (#3779). pub(crate) fn give_back_tool(&mut self, view: ViewInfo) -> Result<()> { let Some(lender) = self.lender.take() else { return Ok(()) }; + // The points the lent tool left picked go back to the Eyedropper, none when it unpicked + // them all (#8090). Group Selection picks no mesh points, so the Eyedropper keeps its own. + let mesh_points = + (lender.id() == "eyedropper" && self.tool.id() != "groupSelection").then(|| self.tool.options().get("meshPoints").cloned()).flatten(); let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx)); let r = self.apply_actions(acts); self.keep_tool_settings(); self.tool = lender; + if let Some(points) = mesh_points { + self.tool.set_option("meshPoints", &points); + } // A gesture that left the selection as it found it (a Shift marquee over nothing) picked // nothing: the selection keeps what it was, the Pen's last anchor or an earlier pick. let left = self.active().map(|d| (d.uid, d.selection.clone()));