From 8051a7face01a693c5afe4860b4b878bed3c6db2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 17:14:01 -0800 Subject: [PATCH] Live Paint: art drawn in a group under a part's name is not counted as a part Faces and edges are the group's paths named Face or Edge, so type or a group drawn in an isolated Live Paint group under one of those names is no longer counted by Gap Options, Info or Make, and Expand keeps it, as it keeps type named like the sources group. Exit Isolation Mode while editing a pattern, an opacity mask or a symbol applies a shape still being drawn with Real-time Drawing and Editing off before the paths drawn in an isolated Live Paint group join it. --- crates/engine/src/cmd/buildcmds/live_paint.rs | 12 ++-- crates/engine/src/cmd/object/arrange.rs | 1 + crates/engine/src/tests/build.rs | 57 +++++++++++++++++++ crates/tools/src/builder/lookup.rs | 10 +++- 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/buildcmds/live_paint.rs b/crates/engine/src/cmd/buildcmds/live_paint.rs index 301ff55a4b..2eea5c2c00 100644 --- a/crates/engine/src/cmd/buildcmds/live_paint.rs +++ b/crates/engine/src/cmd/buildcmds/live_paint.rs @@ -1,8 +1,8 @@ use super::{ Appearance, AppearanceItem, Arc, Beside, Document, EDGE_NAME, EngineError, FACE_NAME, GapOptions, GapSize, LIVE_PAINT_NAME, Node, NodeId, - PathData, Point, Rect, Result, SOURCES_NAME, Selection, Session, SubPath, Value, b, bad, build_children, edge_near, face_at, finite, - fit_to_old_edge, ids_json, is_live_paint, json, number_or, object_param, paint_from, po, point_param, repaint_from, replace_roots, root_ids, - source_nodes, source_shapes, switch_or, + PathData, Point, Rect, Result, Selection, Session, SubPath, Value, b, bad, build_children, edge_near, face_at, finite, fit_to_old_edge, ids_json, + is_live_paint, json, number_or, object_param, paint_from, po, point_param, repaint_from, replace_roots, root_ids, source_nodes, source_shapes, + switch_or, }; /// `options` as stored on a Live Paint group: none for the defaults. @@ -306,10 +306,12 @@ pub(super) fn lp_expand(s: &mut Session, p: &Value) -> Result { e.trace = None; e.live_paint_gaps = None; } + // Objects drawn in the group ([`others_in`]) stay, whatever they are named. + let src = b::sources(n).map(|c| c.id); if let Some(ch) = n.children_mut() { ch.retain(|c| match c.name.as_deref() { - Some(SOURCES_NAME) => false, - Some(FACE_NAME | EDGE_NAME) => draws(c), + _ if Some(c.id) == src => false, + Some(FACE_NAME | EDGE_NAME) if c.path_data().is_some() => draws(c), _ => true, }); } diff --git a/crates/engine/src/cmd/object/arrange.rs b/crates/engine/src/cmd/object/arrange.rs index 9a8414bc8b..25a87c3a2f 100644 --- a/crates/engine/src/cmd/object/arrange.rs +++ b/crates/engine/src/cmd/object/arrange.rs @@ -406,6 +406,7 @@ pub(super) fn exit_isolation(s: &mut Session, p: &Value) -> Result { }; if let Some(leave_mode) = leave_mode { if let Some(i) = st.isolation { + crate::cmd::settle_interaction(s)?; add_drawn_live_paint(s, i, None)?; crate::cmd::distortcmds::finish_edit_text(s.doc_mut()?, i); } diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index 553fb2fb21..8a0ba40084 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -4932,6 +4932,63 @@ fn live_paint_isolation_keeps_art_named_like_its_parts() { assert_eq!(s.doc().unwrap().doc.parent_of(text), Some(g), "Gap Options keeps the type named like the sources"); } +/// Type drawn in an isolated Live Paint group under the name of a face, an edge or the sources +/// group is not one of the group's parts: Gap Options, Info and Make count only the faces and edges +/// Live Paint made, and Expand keeps the type. +#[test] +fn live_paint_does_not_count_art_named_like_its_parts() { + use vectorcraft_tools::builder::{EDGE_NAME, FACE_NAME, SOURCES_NAME}; + let mut s = session(); + let g = live(&mut s); + let edges = s.execute("livePaint.info", &json!({"group": g.0})).unwrap()["edges"].as_array().unwrap().len(); + s.execute("object.isolate", &json!({"id": g.0})).unwrap(); + let mut texts = vec![]; + for (i, name) in [FACE_NAME, EDGE_NAME, SOURCES_NAME].into_iter().enumerate() { + let r = s.execute("text.create", &json!({"x": 20 + 20 * i, "y": 20, "text": "Hi"})).unwrap(); + let t = NodeId(r["id"].as_u64().unwrap()); + s.execute("object.setProps", &json!({"id": t.0, "name": name})).unwrap(); + texts.push(t); + } + s.execute("object.exitIsolation", &json!({})).unwrap(); + let r = s.execute("livePaint.gapOptions", &json!({"ids": [g.0], "detect": true})).unwrap(); + assert_eq!(r["faces"], 3, "Gap Options counts the faces Live Paint made"); + let info = s.execute("livePaint.info", &json!({"group": g.0})).unwrap(); + assert_eq!(info["faces"].as_array().unwrap().len(), 3); + assert_eq!(info["edges"].as_array().unwrap().len(), edges); + let r = s.execute("livePaint.make", &json!({"ids": [g.0]})).unwrap(); + assert_eq!((r["faces"].as_u64(), r["edges"].as_u64()), (Some(3), Some(edges as u64))); + s.execute("livePaint.expand", &json!({"ids": [g.0]})).unwrap(); + let d = &s.doc().unwrap().doc; + for t in texts { + assert_eq!(d.parent_of(t), Some(g), "Expand keeps {t}"); + } +} + +/// With Real-time Drawing and Editing off, a rectangle still being drawn in a Live Paint group +/// isolated in a pattern tile is drawn first when Exit Isolation Mode leaves pattern editing, and +/// joins the group with the tile saved. +#[test] +fn live_paint_in_a_pattern_tile_adds_a_shape_still_being_drawn_on_exit() { + use vectorcraft_tools::builder::{is_live_paint, sources}; + let mut s = session(); + two(&mut s); + s.execute("object.pattern.make", &json!({"name": "P"})).unwrap(); + let g = NodeId(s.execute("livePaint.make", &json!({})).unwrap()["id"].as_u64().unwrap()); + s.execute("object.isolate", &json!({"id": g.0})).unwrap(); + s.execute("prefs.set", &json!({"key": "realTimeDrawing", "value": false})).unwrap(); + let v = ViewInfo::default(); + s.select_tool("rectangle", v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Down, 10.0, 10.0), v).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 40.0, 40.0), v).unwrap(); + assert!(s.interaction_unapplied()); + s.execute("object.exitIsolation", &json!({})).unwrap(); + let st = s.doc().unwrap(); + assert!(st.doc.pattern_edit.is_none()); + let art = &st.doc.pattern("P").unwrap().art; + let n = art.iter().find(|n| is_live_paint(n)).expect("the tile holds the Live Paint group"); + assert_eq!(sources(n).unwrap().children().unwrap().len(), 3, "the rectangle joined the sources"); +} + /// Isolating a level outside an isolated Live Paint group, as the isolation bar's back arrow does, /// leaves the group and adds the paths drawn in it; isolating a path drawn in it does not. #[test] diff --git a/crates/tools/src/builder/lookup.rs b/crates/tools/src/builder/lookup.rs index 0d7acd7e67..7dfa249586 100644 --- a/crates/tools/src/builder/lookup.rs +++ b/crates/tools/src/builder/lookup.rs @@ -38,14 +38,20 @@ fn named(n: &Node, name: &str) -> bool { n.name.as_deref() == Some(name) } +/// Is `n` a Live Paint group's part named `name` ([`FACE_NAME`] or [`EDGE_NAME`]): a path with that +/// name? Type, groups and other objects drawn in the group under such a name are not parts. +fn part(n: &Node, name: &str) -> bool { + named(n, name) && n.path_data().is_some() +} + /// Face children of a Live Paint group (paint order). pub fn faces(group: &Node) -> Vec<&Arc> { - group.children().map(|c| c.iter().filter(|n| named(n, FACE_NAME)).collect()).unwrap_or_default() + group.children().map(|c| c.iter().filter(|n| part(n, FACE_NAME)).collect()).unwrap_or_default() } /// Edge children of a Live Paint group. pub fn edges(group: &Node) -> Vec<&Arc> { - group.children().map(|c| c.iter().filter(|n| named(n, EDGE_NAME)).collect()).unwrap_or_default() + group.children().map(|c| c.iter().filter(|n| part(n, EDGE_NAME)).collect()).unwrap_or_default() } /// The hidden sources group of a Live Paint group.