Merge pull request #10660 from dotCooCoo/fix/newgroup-keeps-tracing

Image Trace: object.newGroup at index 0 no longer ends a tracing
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-03 07:35:43 -08:00
commit 041c6cbfe9
4 files changed
+26 -4

No files matched your search

+6 -2
View File
@@ -106,8 +106,8 @@ pub(super) fn group(s: &mut Session, _: &Value) -> Result<Value> {
}
/// `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<Value> {
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<Value> {
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();
+1 -1
View File
@@ -142,7 +142,7 @@ pub fn specs() -> Vec<CommandSpec> {
"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
),
@@ -1418,6 +1418,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");
+3 -1
View File
@@ -3361,7 +3361,9 @@ through `$`:
collection whose document, layer or group was deleted throws `Stale page item` or `Stale document` first.
- `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`.