Live Paint: leaving nested isolated Live Paint groups adds the drawn paths to each

Leaving isolation mode in a Live Paint group drawn in another isolated
Live Paint group, and that group too (object.exitIsolation, or
object.isolate on a level outside both), now adds the drawn paths to each
group, innermost first, one undo step each, so the inner group joins the
outer one. Before, only the innermost group took its paths, and the inner
group and the paths drawn directly in the outer group stayed beside the
outer group's faces.

A Live Paint group drawn in another one now counts as drawn art: its
hidden sources group no longer keeps it out of the outer group.
This commit is contained in:
dotCooCoo
2026-11-17 11:14:38 -08:00
parent 0aede64dbd
commit 8887fc9d00
7 changed files with 76 additions and 18 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ mod shape_builder;
mod trace;
pub use live_paint::live_paint_gaps;
pub(crate) use live_paint::{LivePaintMove, check_part_name, clear_part_name, isolated_live_paint, merge_drawn_in_isolation};
pub(crate) use live_paint::{LivePaintMove, check_part_name, clear_part_name, isolated_live_paints, merge_drawn_in_isolation};
use live_paint::{lp_expand, lp_fill, lp_gap_options, lp_info, lp_make, lp_merge, lp_release, lp_stroke_edge};
use shape_builder::{sb_merge, sb_regions};
pub(crate) use trace::TracePresetChanges;
+10 -7
View File
@@ -265,19 +265,22 @@ pub(super) fn lp_merge(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "id": id.0, "faces": faces, "edges": edges }))
}
/// The Live Paint group whose drawn art is added when isolation mode leaves `isolated`: the innermost
/// Live Paint group that is `isolated` or holds it, such as a group drawn in an isolated Live Paint
/// group and then isolated itself. None when `isolated` is not in a Live Paint group.
pub(crate) fn isolated_live_paint(d: &Document, isolated: NodeId) -> Option<NodeId> {
d.ancestry(isolated)?.into_iter().rev().find(|id| d.node(*id).is_some_and(is_live_paint))
/// The Live Paint groups whose drawn art can be added when isolation mode leaves `isolated`, innermost
/// first: every Live Paint group that is `isolated` or holds it, such as a group drawn in an isolated
/// Live Paint group and then isolated itself, and the group it was drawn in. Empty when `isolated` is
/// not in a Live Paint group.
pub(crate) fn isolated_live_paints(d: &Document, isolated: NodeId) -> Vec<NodeId> {
d.ancestry(isolated).unwrap_or_default().into_iter().rev().filter(|id| d.node(*id).is_some_and(is_live_paint)).collect()
}
/// The children of Live Paint group `g` besides its parts ([`others_in`]) that Live Paint takes
/// ([`b::live_paint_takes`]) and that are shown and unlocked with everything in them, back to
/// front: the paths drawn in it in isolation mode.
/// front: the paths drawn in it in isolation mode. A Live Paint group's sources group, which is
/// always hidden, does not count.
fn drawn_in(g: &Node) -> Vec<NodeId> {
fn open(n: &Node) -> bool {
n.visible && !n.locked && n.children().is_none_or(|ch| ch.iter().all(|c| open(c)))
let src = b::sources(n).filter(|_| is_live_paint(n)).map(|s| s.id);
n.visible && !n.locked && n.children().is_none_or(|ch| ch.iter().filter(|c| Some(c.id) != src).all(|c| open(c)))
}
others_in(g).filter(|c| open(c) && b::live_paint_takes(c)).map(|c| c.id).collect()
}
+12 -7
View File
@@ -371,16 +371,21 @@ pub(super) fn isolate(s: &mut Session, p: &Value) -> Result<Value> {
}
/// Leaving isolation mode in `isolated` for `next` (None: out of isolation mode) adds the paths drawn
/// in the Live Paint group isolation put new art in to that group, as `livePaint.merge` does, in one
/// undo step ([`crate::cmd::buildcmds::merge_drawn_in_isolation`]), unless `next` is that group or is
/// inside it; → the group when paths were added.
/// in each Live Paint group that is `isolated` or holds it to that group, as `livePaint.merge` does,
/// innermost group first, one undo step per group ([`crate::cmd::buildcmds::merge_drawn_in_isolation`]).
/// A group that `next` is or is inside is skipped, since isolation stays in it. → the outermost group
/// that paths were added to.
fn add_drawn_live_paint(s: &mut Session, isolated: NodeId, next: Option<NodeId>) -> Result<Option<NodeId>> {
let d = &s.doc()?.doc;
let Some(g) = crate::cmd::buildcmds::isolated_live_paint(d, isolated) else { return Ok(None) };
if next.is_some_and(|n| d.ancestry(n).is_some_and(|a| a.contains(&g))) {
return Ok(None);
let stays = next.and_then(|n| d.ancestry(n)).unwrap_or_default();
let left: Vec<NodeId> = crate::cmd::buildcmds::isolated_live_paints(d, isolated).into_iter().filter(|g| !stays.contains(g)).collect();
let mut added = None;
for g in left {
if crate::cmd::buildcmds::merge_drawn_in_isolation(s, g)? {
added = Some(g);
}
}
Ok(crate::cmd::buildcmds::merge_drawn_in_isolation(s, g)?.then_some(g))
Ok(added)
}
pub(super) fn exit_isolation(s: &mut Session, p: &Value) -> Result<Value> {
+1 -1
View File
@@ -250,7 +250,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Exit Isolation Mode",
[],
None,
"{} leave isolation mode; leaving an isolated Live Paint group adds the paths, compound paths and groups of them drawn in it (shown and unlocked with everything in them) to the group as livePaint.merge does, in one undo step, and leaves type, images and other objects in it as they are; object.isolate on a level outside the group does the same",
"{} leave isolation mode; leaving an isolated Live Paint group adds the paths, compound paths and groups of them drawn in it (shown and unlocked with everything in them) to the group as livePaint.merge does, in one undo step, and leaves type, images and other objects in it as they are; object.isolate on a level outside the group does the same. Leaving a Live Paint group drawn in another isolated Live Paint group, and that group too, does this for each, innermost first, one undo step each",
has_doc,
exit_isolation
),
+49
View File
@@ -5102,6 +5102,55 @@ fn live_paint_isolation_adds_a_drawn_group_isolated_inside_it() {
}
}
/// With Live Paint group `inner` made in isolated Live Paint group `outer` and then isolated itself,
/// leaving both levels (`object.exitIsolation`, or `object.isolate` on the layer) adds the path drawn
/// in `inner` to it and then `inner` and the path drawn directly in `outer` to `outer`, one undo step
/// each. Isolating `outer` from `inner` adds only `inner`'s drawn path, and `outer` keeps its own.
#[test]
fn live_paint_isolation_merges_nested_live_paint_groups_it_leaves() {
use vectorcraft_tools::builder::{faces, sources};
for to in ["exit", "layer", "outer"] {
let mut s = session();
let outer = live(&mut s);
let layer = s.doc().unwrap().doc.parent_of(outer).unwrap();
s.execute("object.isolate", &json!({"id": outer.0})).unwrap();
let a = line_across(&mut s, 50.0);
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(outer));
let inner = live(&mut s);
assert_eq!(s.doc().unwrap().doc.parent_of(inner), Some(outer), "the inner group is drawn in the outer one");
s.execute("object.isolate", &json!({"id": inner.0})).unwrap();
let b = line_across(&mut s, 30.0);
assert_eq!(s.doc().unwrap().doc.parent_of(b), Some(inner));
let steps = s.doc().unwrap().history.undo.len();
match to {
"exit" => s.execute("object.exitIsolation", &json!({})).unwrap(),
"layer" => s.execute("object.isolate", &json!({"id": layer.0})).unwrap(),
_ => s.execute("object.isolate", &json!({"id": outer.0})).unwrap(),
};
let d = &s.doc().unwrap().doc;
if to == "outer" {
assert_eq!(s.doc().unwrap().isolation, Some(outer));
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "only the inner group's path joins");
let n = node(&s, inner);
assert_eq!(d.parent_of(b), Some(sources(&n).unwrap().id), "the path drawn in the inner group joined it");
assert_eq!(d.parent_of(inner), Some(outer), "the inner group stays drawn in the outer one");
assert_eq!(d.parent_of(a), Some(outer), "the path drawn in the outer group stays as drawn");
continue;
}
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "{to}: one undo step for each group");
assert!(d.node(inner).is_none(), "{to}: the inner group joined the outer one");
let n = node(&s, outer);
let src = sources(&n).unwrap().id;
assert_eq!(d.parent_of(a), Some(src), "{to}: the path drawn in the outer group joined it");
assert!(d.ancestry(b).unwrap().contains(&src), "{to}: the path drawn in the inner group is among the outer group's paths");
assert!(n.children().unwrap().iter().all(|c| c.id == src || c.path_data().is_some()), "{to}: only parts are left in the outer group");
assert!(faces(&n).len() > 3, "{to}: the added paths cut the outer group's faces");
if to == "exit" {
assert_eq!(s.doc().unwrap().selection.objects, vec![outer]);
}
}
}
/// A line from left of the [`live`] group to its right face, so it cuts the two faces left of it.
fn line_to_right_face(s: &mut Session, y: f64) -> NodeId {
let r = s.execute("path.create", &json!({"anchors": [{"x": -10, "y": y}, {"x": 105, "y": y}]})).unwrap();