diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index bca6e5fdb65..5249ccee0bb 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -575,7 +575,7 @@ fn build() -> Vec { dup.name.clone_from(name); } let nid = doc.insert_above(Some(id), dup); - // The copy starts unlinked from its original, as in Photoshop (#11217). + // A lone copy joins its original's link group, as in the reference application (#11217). crate::layer_multi_cmds::relink_copies(doc, &[nid])?; if !in_place { crate::artboard_cmds::place_copy(doc, nid)?; diff --git a/crates/engine/src/cmd/edit_cmds.rs b/crates/engine/src/cmd/edit_cmds.rs index 0df1075e0a9..509abf3d2a4 100644 --- a/crates/engine/src/cmd/edit_cmds.rs +++ b/crates/engine/src/cmd/edit_cmds.rs @@ -610,7 +610,7 @@ fn layer_via(s: &mut Session, cut: bool) -> Result { dup.name = doc.copy_name(&src.name); dup.locks = Default::default(); let nid = doc.insert_above(Some(id), dup); - // The copy starts unlinked from its original, as in Photoshop (#11217). + // A lone copy joins its original's link group, as in the reference application (#11217). crate::layer_multi_cmds::relink_copies(doc, &[nid])?; *active = Some(nid); Ok(nid) diff --git a/crates/engine/src/cmd/layer_multi_cmds/structure.rs b/crates/engine/src/cmd/layer_multi_cmds/structure.rs index 6f3d722ab71..c6cd8c1520d 100644 --- a/crates/engine/src/cmd/layer_multi_cmds/structure.rs +++ b/crates/engine/src/cmd/layer_multi_cmds/structure.rs @@ -297,13 +297,20 @@ pub fn duplicate_selected(s: &mut Session, in_place: bool, label: &str) -> Resul Ok(json!({"layers": out, "layer": active.map(|l| l.0)})) } -/// Duplicates start outside their originals' link groups, as in Photoshop (#11217): a copy that -/// joined the original's group would drag the originals along with it (⌥⌘T's box over the copy -/// framed them too). Copies of several layers of one link group stay linked to each other, under -/// a group of their own, as `layer_copy_cmds::adapt_copies` remaps copies landing in another -/// document; a lone copy of a linked layer is unlinked. `copies` are the copies just inserted in -/// `doc` (the layers in copied groups are remapped with them); the originals keep their groups. +/// Link groups of fresh copies, as the reference application does (measured, #11217): a copy of +/// one layer alone (Duplicate, Layer via Copy) joins its original's link group. With several +/// layers copied, the copies of several layers of one link group are linked to each other under a +/// group of their own, as `layer_copy_cmds::adapt_copies` remaps copies landing in another +/// document, and a copy that is the only one from its link group is unlinked. `copies` are the +/// copies just inserted in `doc` (the layers in copied groups are remapped with them); the +/// originals keep their groups. pub(crate) fn relink_copies(doc: &mut Document, copies: &[LayerId]) -> Result<()> { + // One layer copied on its own keeps the link group it was copied with. + if let [only] = copies + && doc.layer(*only).is_some_and(|l| !matches!(l.content, LayerContent::Group(_))) + { + return Ok(()); + } // Every copied layer with the link group it was copied with. An explicit stack rather than // recursion: documents can nest deeply. let mut linked: Vec<(LayerId, u64)> = Vec::new(); diff --git a/crates/engine/src/cmd/layer_multi_cmds/tests.rs b/crates/engine/src/cmd/layer_multi_cmds/tests.rs index ca20aeefd5c..0d27dab4a3b 100644 --- a/crates/engine/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine/src/cmd/layer_multi_cmds/tests.rs @@ -1473,15 +1473,16 @@ fn linked_pair() -> (Session, LayerId, LayerId, LayerId, Option) { (s, a, b, c, group) } -/// #11217 review: a copy of one linked layer starts unlinked, as in Photoshop, so ⌥⌘T's box over -/// the copy doesn't take the originals along. The originals stay linked. +/// #11217: a copy of one linked layer alone joins its original's link group; copied together with +/// an unlinked layer it is unlinked (both measured in the reference application). The originals +/// stay linked. #[test] -fn duplicating_one_linked_layer_leaves_the_copy_unlinked() { +fn duplicating_one_linked_layer_keeps_the_copy_in_its_link_group() { let (mut s, a, b, c, group) = linked_pair(); - // One layer (what ⌥⌘T duplicates), and with an unlinked layer beside it (several selected). + // One layer, and with an unlinked layer beside it (several selected). s.execute("layer.select", json!({"layer": a.0})).unwrap(); let copy = LayerId(s.execute("layer.duplicate", json!({"inPlace": true})).unwrap()["layer"].as_u64().unwrap()); - assert_eq!(link_group(&s, copy), None, "the copy is unlinked"); + assert_eq!(link_group(&s, copy), group, "the lone copy joins the originals' link group"); select_all(&mut s, &[a, c]); let r = s.execute("layer.duplicate", json!({})).unwrap(); let copies: Vec = r["layers"].as_array().unwrap().iter().map(|v| LayerId(v.as_u64().unwrap())).collect(); @@ -1491,14 +1492,14 @@ fn duplicating_one_linked_layer_leaves_the_copy_unlinked() { } /// #11217 review: copy-dragging layers in the panel goes through `apply_move`, which must -/// relink its copies the way Duplicate does: a lone copy unlinked, a copied pair linked to -/// each other under a fresh group, never to the originals. +/// relink its copies the way Duplicate does: a lone copy joins its original's link group, a +/// copied pair is linked to each other under a fresh group, not to the originals. #[test] fn copy_dragging_linked_layers_relinks_the_copies() { let (mut s, a, b, c, group) = linked_pair(); let r = s.execute("layer.moveTo", json!({"layer": a.0, "target": c.0, "position": "above", "copy": true})).unwrap(); let copy = LayerId(r["layer"].as_u64().unwrap()); - assert_eq!(link_group(&s, copy), None, "the copy-dragged copy is unlinked"); + assert_eq!(link_group(&s, copy), group, "the lone copy-dragged copy joins the originals' link group"); assert_eq!((link_group(&s, a), link_group(&s, b)), (group, group), "the originals keep their links"); let r = s.execute("layer.moveTo", json!({"layers": [a.0, b.0], "target": c.0, "position": "above", "copy": true})).unwrap(); @@ -1529,16 +1530,16 @@ fn duplicating_a_linked_pair_links_the_copies_to_each_other() { assert_eq!((bounds(&s, a), bounds(&s, b)), (a0, b0)); } -/// #11217 review: Layer via Copy of one linked layer (no selection) starts unlinked too — the -/// same rule as `layer.duplicate`, on its own code path in `layer_via`. +/// #11217: Layer via Copy of one linked layer (no selection) joins its original's link group too +/// (measured): the same rule as `layer.duplicate`, on its own code path in `layer_via`. #[test] -fn layer_via_copy_of_one_linked_layer_leaves_the_copy_unlinked() { +fn layer_via_copy_of_one_linked_layer_keeps_the_copy_in_its_link_group() { let (mut s, a, b, _, group) = linked_pair(); let layers = doc(&s).layers.len(); s.execute("layer.select", json!({"layer": a.0})).unwrap(); let copy = LayerId(s.execute("layer.new.layerViaCopy", json!({})).unwrap()["layer"].as_u64().unwrap()); assert_eq!(doc(&s).layers.len(), layers + 1, "only the active layer is copied"); - assert_eq!(link_group(&s, copy), None, "the copy is unlinked"); + assert_eq!(link_group(&s, copy), group, "the lone copy joins the originals' link group"); assert_eq!((link_group(&s, a), link_group(&s, b)), (group, group), "the originals keep their links"); }