From 4a65fef4101594d63fb064e992a5b6a0b27a3df5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 12:36:14 -0800 Subject: [PATCH] Live Paint: adding a fill or stroke to the contents of a group with only source paths changes nothing A selected Live Paint group left with only its hidden source paths is still a selection, so appearance.addFill and appearance.addStroke with target contents return without a change instead of reporting an empty selection. An empty selection is still refused. --- crates/engine/src/cmd/appearance.rs | 11 ++++++++++- crates/engine/src/tests/build.rs | 23 +++++++++++++++++++++++ docs/mcp.md | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index b33af177bb..3b23d62634 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -925,7 +925,16 @@ fn set_active_item(s: &mut Session, p: &Value) -> Result { fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result { let cmd = if fill { "appearance.addFill" } else { "appearance.addStroke" }; - let mut ids = require_targets(s, p, cmd)?; + let mut ids = row_targets(s, p, cmd)?; + if ids.is_empty() { + // A selected Live Paint group left with only its hidden source paths has nothing to edit: it is + // still a selection, so the edit changes nothing. + let roots = appearance_roots(s, p)?; + if targets_contents(p)? && !roots.is_empty() && !super::paint::live_paint_split(&s.doc()?.doc, &roots).2.is_empty() { + return ok(); + } + return Err(bad(cmd, "select objects or give ids")); + } // In the contents of a Live Paint group, a new fill goes on its faces and a new stroke on its edges; // with no part of that kind, nothing changes. let skipped = contents_skipped(s, p, fill)?; diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index f7c410800a..7b709a4ad2 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -4486,6 +4486,29 @@ fn live_paint_group_with_only_source_paths_leaves_new_art_alone_for_a_contents_e assert_eq!((s.paint.clone(), s.new_art_stroke()), (paint0, stroke0), "new art keeps its stroke"); } +/// Adding a fill or a stroke to the contents of a Live Paint group left with only its hidden source paths +/// succeeds and changes nothing, while an empty selection is still refused. +#[test] +fn live_paint_group_with_only_source_paths_ignores_add_fill_and_add_stroke_of_its_contents() { + let mut s = session(); + let g = live(&mut s); + let n = node(&s, g); + let parts: Vec = vectorcraft_tools::builder::faces(&n).iter().chain(vectorcraft_tools::builder::edges(&n).iter()).map(|p| p.id).collect(); + s.edit("t", |d, _| { + d.children_mut(Some(g)).unwrap().retain(|c| !parts.contains(&c.id)); + Ok(()) + }) + .unwrap(); + s.execute("select.set", &json!({"ids": [g.0]})).unwrap(); + let before = node(&s, g); + for cmd in ["appearance.addFill", "appearance.addStroke"] { + s.execute(cmd, &json!({"target": "contents"})).unwrap(); + assert_eq!(node(&s, g), before, "{cmd} changes nothing"); + } + s.execute("select.none", &json!({})).unwrap(); + assert!(s.execute("appearance.addFill", &json!({"target": "contents"})).is_err(), "no selection is still refused"); +} + /// A selected Live Paint group with no part of the edited kind is still a selection: a stroke edit /// of a group without edges, or a fill gradient edit of a group without faces, changes nothing and /// leaves the settings for new art as they are. diff --git a/docs/mcp.md b/docs/mcp.md index 203e6e5788..a5614e33a7 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5520,7 +5520,7 @@ fills and strokes above it paint over the members (characters), those below unde `appearance.contents_index`. The `appearance.*`, `effect.*` and `graphicStyle.apply` commands edit the selected objects themselves (a group's own stack; layers through `ids`) or, with `target: "contents"`, the objects inside the groups and layers. In a Live Paint group those are its faces and edges, not its hidden source paths. -`appearance.addFill` adds a fill to the faces only, and `appearance.addStroke` adds a stroke to the edges only. A +`appearance.addFill` adds a fill to the faces only, and `appearance.addStroke` adds a stroke to the edges only; a selected group left with only its hidden source paths is returned without a change. A fill or stroke command with an `item` and `target: "contents"` (such as `paint.setFill`, `stroke.set`, `paint.invert`, `paint.setGradientGeom` and `object.setOverprint`) changes the faces for a fill row and the edges for a stroke row. The row commands (`appearance.setItem`, `appearance.removeItem` and the others) find their rows on each