From d3eb174b6d6e9fba6d323c58c3a573788d537459 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 19:07:05 -0800 Subject: [PATCH] Image Trace: object.newGroup at index 0 no longer ends a tracing An Image Trace object keeps its source image as its first child. object.newGroup with index 0 put the new group below that image, so the group stopped being a tracing. Index 0 in an Image Trace object is now refused before anything changes; index 1 puts the group directly above the source image. The index parameter came with #9048. --- crates/engine/src/cmd/object/arrange.rs | 8 ++++++-- crates/engine/src/cmd/object/commands.rs | 2 +- crates/engine/src/tests/script_dom_tracing.rs | 16 ++++++++++++++++ docs/mcp.md | 4 +++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/object/arrange.rs b/crates/engine/src/cmd/object/arrange.rs index 955520427c..8ed4656295 100644 --- a/crates/engine/src/cmd/object/arrange.rs +++ b/crates/engine/src/cmd/object/arrange.rs @@ -106,8 +106,8 @@ pub(super) fn group(s: &mut Session, _: &Value) -> Result { } /// `object.newGroup`: an empty group, or with `compound` an empty compound path, in a layer or a -/// group (default: the current layer), on top of its contents or at `index` (0 = bottom). The -/// selection stays as it is. +/// group (default: the current layer), on top of its contents or at `index` (0 = bottom; refused +/// in an Image Trace object, whose source image stays at the bottom). The selection stays as it is. pub(super) fn new_group(s: &mut Session, p: &Value) -> Result { const C: &str = "object.newGroup"; // Only an omitted key takes its default; `null` is refused like any other bad value. @@ -132,6 +132,10 @@ pub(super) fn new_group(s: &mut Session, p: &Value) -> Result { if !d.is_editable(parent) { return Err(bad(C, "the layer or group is hidden or locked")); } + // An Image Trace object keeps its source image first; a group below it would end the tracing. + if index == 0 && crate::cmd::is_trace_group(n) { + return Err(bad(C, "index 0 of an Image Trace object is its source image; use index 1 or more")); + } let label = if compound { "Compound Path" } else { "Group" }; let gid = s.edit(label, |d, _| { let gid = d.alloc_id(); diff --git a/crates/engine/src/cmd/object/commands.rs b/crates/engine/src/cmd/object/commands.rs index bea69d1698..4f9b2887ba 100644 --- a/crates/engine/src/cmd/object/commands.rs +++ b/crates/engine/src/cmd/object/commands.rs @@ -142,7 +142,7 @@ pub fn specs() -> Vec { "Group", [], None, - "{parent?: layer or group id (default: the current layer), index?: n (0 = bottom, or directly above the clipping path in a clipping layer or group; default: on top), compound?: bool (default false; true: an empty compound path instead of a group)} → {id}: an empty group or compound path in a shown, unlocked layer or group; an omitted key takes its default; null is refused for parent, index and compound; the selection stays as it is", + "{parent?: layer or group id (default: the current layer), index?: n (0 = bottom, or directly above the clipping path in a clipping layer or group; 0 is refused in an Image Trace object, whose source image stays at the bottom; default: on top), compound?: bool (default false; true: an empty compound path instead of a group)} → {id}: an empty group or compound path in a shown, unlocked layer or group; an omitted key takes its default; null is refused for parent, index and compound; the selection stays as it is", has_doc, new_group ), diff --git a/crates/engine/src/tests/script_dom_tracing.rs b/crates/engine/src/tests/script_dom_tracing.rs index 24223785dd..0d28c8c8e9 100644 --- a/crates/engine/src/tests/script_dom_tracing.rs +++ b/crates/engine/src/tests/script_dom_tracing.rs @@ -1271,6 +1271,22 @@ fn unimplemented_tracing_members_are_not_reported() { let _ = std::fs::remove_dir_all(base); } +#[test] +fn new_group_at_the_bottom_of_a_tracing_is_refused() { + let base = folder("new-group-bottom"); + let (mut s, id) = session(&base, false); + let tid = NodeId(s.execute("imageTrace.make", &json!({"id": id.0})).unwrap()["id"].as_u64().unwrap()); + let steps = undo_steps(&s); + let e = s.execute("object.newGroup", &json!({"parent": tid.0, "index": 0})).unwrap_err().to_string(); + assert!(e.contains("source image"), "{e}"); + assert_eq!(traces(&s), [tid]); + assert_eq!(undo_steps(&s), steps); + let g = NodeId(s.execute("object.newGroup", &json!({"parent": tid.0, "index": 1})).unwrap()["id"].as_u64().unwrap()); + assert_eq!(traces(&s), [tid]); + assert_eq!(s.active().unwrap().doc.children(Some(tid)).unwrap()[1].id, g); + let _ = std::fs::remove_dir_all(base); +} + #[test] fn retrace_keeps_the_tracing_opacity_and_blend_mode() { let base = folder("retrace-appearance"); diff --git a/docs/mcp.md b/docs/mcp.md index b3c7372984..35772df192 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3337,7 +3337,9 @@ through `$`: `GroupItems.createFromFile` throw an error that says they are not available yet. - `object.newGroup {parent?, index?, compound?}` adds an empty group to a shown, unlocked layer or group (`parent`; default: the current layer), on top of its contents or at `index` (0 is the bottom; in a clipping layer or group, - index 0 puts it directly above the clipping path), as one undo step named Group, and + index 0 puts it directly above the clipping path; in an Image Trace object, index 0 is refused and changes nothing, + since the source image stays at the bottom, and index 1 puts it directly above the source image), as one undo step + named Group, and gives `{id}`. With `compound: true` it adds an empty compound path instead, as one undo step named Compound Path. An omitted key takes its default (`parent`: the current layer; `index`: on top; `compound`: false). Explicit `null` is refused for `parent`, `index` and `compound`.