Screen print marks: marks copied from an unnamed layer paste back into the marks layer

A layer without a name gives a copied object no source layer, so Paste
Remembers Layers returned early and a marks group copied with an artboard
from an unnamed marks layer went into the ordinary paste layer. The marks
check now runs before that return; ordinary art with no source layer still
pastes where it did.
This commit is contained in:
dotCooCoo committed 2026-12-04 01:17:12 -08:00
1 parent d72a82de1c
commit e91a7fe0fe
2 files changed
+29 -4

No files matched your search

@@ -383,6 +383,20 @@ 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_copied_from_an_unnamed_marks_layer_paste_back_into_it() {
let mut s = session();
let r = run(&mut s, json!({}));
let layer = NodeId(r["layer"].as_u64().unwrap());
let st = s.doc_mut().unwrap();
std::sync::Arc::make_mut(&mut st.doc).node_mut(layer).unwrap().name = None;
s.execute("artboard.copy", &json!({"index": 0, "art": true, "lockedAndHidden": true})).unwrap();
s.execute("edit.paste", &json!({})).unwrap();
let marks = |s: &Session| s.doc().unwrap().doc.node(layer).map(|l| (l.locked, l.children().map_or(0, |k| k.len())));
assert_eq!(s.doc().unwrap().doc.artboards.len(), 2);
assert_eq!(marks(&s), Some((true, 2)), "the pasted marks go into the unnamed marks layer, which stays locked");
}
#[test]
fn marks_pasted_into_another_document_go_into_its_marks_layer_not_a_layer_of_the_same_name() {
let mut s = session();
+15 -4
View File
@@ -1876,6 +1876,11 @@ fn remembered_layers(d: &Document, sources: &[Option<SourceLayer>], marks: &[boo
.iter()
.enumerate()
.map(|(k, src)| {
// A marks group goes into the marks layer even when the layer it was copied from has
// no name.
if marks.get(k).copied().unwrap_or(false) && src.is_none() {
return Ok(Some(marks_layer_target(d)));
}
let Some(src) = src else { return Ok(None) };
let key = (src, marks.get(k).copied().unwrap_or(false));
if let Some(r) = found.get(&key) {
@@ -1900,10 +1905,7 @@ fn remembered_layer(d: &Document, src: &SourceLayer, marks: bool, same_doc: bool
// A marks group goes into the document's marks layer, never into an ordinary layer of the
// same name.
if marks {
return Ok(match super::addons::screen_marks_layer(d) {
Some(l) => Remembered::Layer(l),
None => Remembered::Make { parent: None, names: vec![super::addons::SCREEN_MARKS_LAYER.to_string()] },
});
return Ok(marks_layer_target(d));
}
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) {
@@ -1929,6 +1931,15 @@ fn remembered_layer(d: &Document, src: &SourceLayer, marks: bool, same_doc: bool
})
}
/// Where a screen print marks group goes: the document's marks layer, locked or hidden as it is,
/// or a new top-level marks layer when the document has none.
fn marks_layer_target(d: &Document) -> Remembered {
match super::addons::screen_marks_layer(d) {
Some(l) => Remembered::Layer(l),
None => Remembered::Make { parent: None, names: vec![super::addons::SCREEN_MARKS_LAYER.to_string()] },
}
}
/// The deepest chain of layers inside `parent` (none: the top level) named `names` one inside the
/// other: its last layer (`parent` when none matches), how many names it matched and whether all
/// its layers are shown and unlocked. Of chains as deep, the topmost shown and unlocked one wins.