mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 23:50:13 +00:00
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.
This commit is contained in:
@@ -925,7 +925,16 @@ fn set_active_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result<Value> {
|
||||
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)?;
|
||||
|
||||
@@ -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<NodeId> = 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.
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user