diff --git a/crates/engine/src/cmd/addons/color/screen_marks/tests.rs b/crates/engine/src/cmd/addons/color/screen_marks/tests.rs index 76c2c9f799..fd1912756d 100644 --- a/crates/engine/src/cmd/addons/color/screen_marks/tests.rs +++ b/crates/engine/src/cmd/addons/color/screen_marks/tests.rs @@ -383,6 +383,37 @@ fn marks_copied_with_an_artboard_paste_back_into_their_locked_layer() { assert_eq!(marks(&s), Some((true, 2)), "marking the pasted artboard replaces the pasted copy"); } +#[test] +fn marks_pasted_into_another_document_go_into_its_marks_layer_not_a_layer_of_the_same_name() { + let mut s = session(); + run(&mut s, json!({})); + s.execute("artboard.copy", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap(); + s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap(); + let r = run(&mut s, json!({})); + let layer = NodeId(r["layer"].as_u64().unwrap()); + let plain = NodeId(s.execute("layer.new", &json!({"name": LAYER_NAME})).unwrap()["id"].as_u64().unwrap()); + s.execute("edit.paste", &json!({})).unwrap(); + let kids = |s: &Session, l: NodeId| s.doc().unwrap().doc.node(l).map(|l| (l.locked, l.children().map_or(0, |k| k.len()))); + assert_eq!(s.doc().unwrap().doc.artboards.len(), 2); + assert_eq!(kids(&s, layer), Some((true, 2)), "the pasted marks go into the locked marks layer"); + assert_eq!(kids(&s, plain), Some((false, 0)), "the ordinary layer of the same name stays empty"); +} + +#[test] +fn marks_lying_off_an_artboard_go_with_its_copy_made_by_moving_it() { + let mut s = session(); + let r = run(&mut s, json!({"positions": ["right"], "inset": -200})); + let b = bounds(&node(&s, r["ids"][0].as_u64().unwrap())); + assert!(b.x0 >= 600.0, "the marks lie wholly off the artboard: {b:?}"); + let p = json!({"index": 0, "dy": 500, "copy": true, "moveArt": true, "lockedAndHidden": true}); + s.execute("artboard.move", &p).unwrap(); + let kids = |s: &Session| s.doc().unwrap().doc.layers[0].children().unwrap().len(); + assert_eq!(s.doc().unwrap().doc.artboards.len(), 2); + assert_eq!(kids(&s), 2, "the copy carries a copy of the marks"); + run(&mut s, json!({"artboard": 1, "positions": ["right"], "inset": -200, "size": 30})); + assert_eq!(kids(&s), 2, "marking the copy replaces the copied marks"); +} + #[test] fn other_art_copied_with_an_artboard_does_not_paste_into_a_locked_layer() { let mut s = session(); diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index b005e1e56b..ff90db1370 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -1884,9 +1884,15 @@ fn remembered_layers(d: &Document, sources: &[Option], marks: &[boo /// it still where they were (by id) are kept. Below them, and in another document from the top, /// each name is matched among the layers inside the one above (the topmost of the same name whose /// layers match the most names, a shown and unlocked one first). The names left unmatched are -/// made. A matched layer that is hidden or locked, or inside one that is, is an error, except the -/// marks layer for a screen print marks group (`marks`). +/// made. A matched layer that is hidden or locked, or inside one that is, is an error. A screen +/// print marks group (`marks`) goes into the document's marks layer, locked or hidden as it is, +/// when the document has one. fn remembered_layer(d: &Document, src: &SourceLayer, marks: bool, same_doc: bool) -> Result { + // A marks group goes into the document's marks layer when it has one, not into an ordinary + // layer of the same name. + if marks && let Some(l) = super::addons::screen_marks_layer(d) { + return Ok(Remembered::Layer(l)); + } let held = |id: &NodeId| d.node(*id).is_some_and(|n| n.is_layer() && n.name.as_ref() == src.names.last()); let kept = if same_doc && src.ids.last().is_some_and(held) { src.ids.len() @@ -1901,7 +1907,6 @@ fn remembered_layer(d: &Document, src: &SourceLayer, marks: bool, same_doc: bool let rest = &src.names[kept..]; let (end, matched, _) = named_chain(d, kept.checked_sub(1).map(|j| src.ids[j]), rest); if let Some(l) = end - && !(marks && matched == rest.len() && super::addons::screen_marks_layer(d) == Some(l)) && !d.ancestry(l).is_some_and(|a| a.iter().all(|i| d.node(*i).is_some_and(|n| n.visible && !n.locked))) { return Err(EngineError::Other("the target layer is locked or hidden".into())); diff --git a/crates/engine/src/cmd/xform.rs b/crates/engine/src/cmd/xform.rs index 6656711738..63f47d652a 100644 --- a/crates/engine/src/cmd/xform.rs +++ b/crates/engine/src/cmd/xform.rs @@ -685,16 +685,9 @@ fn artboard_move(s: &mut Session, p: &Value) -> Result { if !copy { super::panelcmds::refuse_locked(&s.doc()?.doc, &indices)?; } - // Each artboard's art, an object counted once (artboards can overlap). - let mut arts: Vec<(usize, Vec)> = vec![]; - for &i in &indices { - let art = super::panelcmds::artboard_art(s, i, move_art, locked_art, !copy)?; - let art = art.into_iter().filter(|id| !arts.iter().any(|(_, a)| a.contains(id))).collect(); - arts.push((i, art)); - } - if copy { - arts = super::panelcmds::marks_with_owners(&s.doc()?.doc, arts); - } + // Each artboard's art, an object counted once (artboards can overlap). A copy also takes each + // copied artboard's screen print marks group, wherever the group lies. + let arts = super::panelcmds::artboards_art(s, &indices, move_art, locked_art, !copy)?; let ids: Vec = arts.iter().flat_map(|(_, a)| a.iter().copied()).collect(); let sc = Scaling { patterns: super::object::transform_patterns(s, p, &ids)?, ..Scaling::default() }; let (index, moved) = s.edit(if copy { "Duplicate Artboard" } else { "Move Artboard" }, |d, _| {