Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Fix #2678: Ungroup no longer multiplies the group's opacity into its members

dotCooCoodb6c5ea9df62
diff --git a/crates/engine/src/cmd/object/arrange.rs b/crates/engine/src/cmd/object/arrange.rs
index 741475d87..9cafae899 100644
--- a/crates/engine/src/cmd/object/arrange.rs
+++ b/crates/engine/src/cmd/object/arrange.rs
@@ -129,7 +129,7 @@ pub(super) fn ungroup(s: &mut Session, _: &Value) -> Result<Value> {
{
*clipping = false;
}
- c.opacity *= n.opacity;
+ // Each member keeps its own opacity; the group's opacity goes with the group.
new_sel.push(c.id);
out.push(c);
}
diff --git a/crates/engine/src/tests/containers.rs b/crates/engine/src/tests/containers.rs
index aa72ebecc..1b147ecc1 100644
--- a/crates/engine/src/tests/containers.rs
+++ b/crates/engine/src/tests/containers.rs
@@ -69,6 +69,28 @@ fn a_group_fill_paints_both_members_and_the_contents_slot_moves() {
assert!(s.execute("appearance.moveItem", &json!({"from": "contents", "to": 1})).is_err());
}
+#[test]
+fn ungroup_leaves_the_groups_opacity_with_the_group() {
+ let mut s = session();
+ let red = id_of(&run(&mut s, "shape.rectangle", json!({"x": 20, "y": 20, "width": 60, "height": 40})));
+ run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));
+ let blue = id_of(&run(&mut s, "shape.rectangle", json!({"x": 100, "y": 20, "width": 60, "height": 40})));
+ run(&mut s, "paint.setFill", json!({"color": "#0000ff"}));
+ run(&mut s, "object.setProps", json!({"ids": [blue.0], "opacity": 40}));
+ run(&mut s, "select.set", json!({"ids": [red.0, blue.0]}));
+ let g = id_of(&run(&mut s, "object.group", json!({})));
+ run(&mut s, "object.setProps", json!({"ids": [g.0], "opacity": 50}));
+ run(&mut s, "object.ungroup", json!({}));
+ // Each member keeps its own opacity: the red square is opaque again and the blue one stays at 40%.
+ assert!((node(&s, red).opacity - 1.0).abs() < 1e-6, "{}", node(&s, red).opacity);
+ assert!((node(&s, blue).opacity - 0.4).abs() < 1e-6, "{}", node(&s, blue).opacity);
+ assert_eq!(pixel(&s, 40, 40), RED);
+ // One undo step brings the group back at 50%.
+ run(&mut s, "edit.undo", json!({}));
+ assert!((node(&s, g).opacity - 0.5).abs() < 1e-6);
+ assert!((node(&s, red).opacity - 1.0).abs() < 1e-6);
+}
+
#[test]
fn appearance_commands_target_the_object_or_its_contents() {
let mut s = session();