Merge pull request #8405 from dotCooCoo/feat/layers-drag-into-live-paint

Layers: dragging a path into a Live Paint group adds it to the group as Live Paint › Merge does
This commit is contained in:
BFlat
2026-11-19 00:41:49 +07:00
committed by GitHub
34 changed files with 695 additions and 30 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::{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;
+241 -12
View File
@@ -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, 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, 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,
};
/// `options` as stored on a Live Paint group: none for the defaults.
@@ -74,6 +74,44 @@ fn set_parts(g: &mut Node, mut parts: Vec<Arc<Node>>, gone: &[NodeId]) {
}
}
/// Whether a path named `name` directly in a Live Paint group is one of its faces or edges: the
/// name is [`FACE_NAME`] or [`EDGE_NAME`].
fn part_name(name: Option<&str>) -> bool {
matches!(name, Some(FACE_NAME | EDGE_NAME))
}
/// Whether `n` is a path whose parent `parent` is a Live Paint group.
fn path_in_live_paint(d: &Document, parent: Option<NodeId>, n: &Node) -> bool {
n.path_data().is_some() && parent.and_then(|p| d.node(p)).is_some_and(is_live_paint)
}
/// Clear the name of `n`, put directly in `parent`, when it is a path named like a face or an edge
/// ([`part_name`]) and `parent` is a Live Paint group, so that the group's other children
/// ([`others_in`]) keep it when its faces and edges are made again. Paste uses it.
pub(crate) fn clear_part_name(d: &Document, parent: Option<NodeId>, n: &mut Node) {
if part_name(n.name.as_deref()) && path_in_live_paint(d, parent, n) {
n.name = None;
}
}
/// Refuse naming rows `ids` `name` when it is the name of a face or an edge ([`part_name`]) and one
/// of them is a path directly in a Live Paint group that is not named `name` already. Checked
/// before anything changes.
pub(crate) fn check_part_name(d: &Document, ids: &[NodeId], name: &str) -> Result<()> {
if !part_name(Some(name)) {
return Ok(());
}
for id in ids {
if let Some(n) = d.node(*id)
&& n.name.as_deref() != Some(name)
&& path_in_live_paint(d, d.parent_of(*id), n)
{
return Err(EngineError::Other("`Face` and `Edge` name the faces and edges of a Live Paint group: give the path another name".into()));
}
}
Ok(())
}
/// Select `ids` alone, without an undo step, when they are not selected that way already.
fn select_only(s: &mut Session, ids: &[NodeId]) -> Result<()> {
let st = s.doc()?;
@@ -149,11 +187,16 @@ fn merge_live(d: &mut Document, sel: &mut Selection, roots: &[NodeId]) -> Result
.ok_or_else(|| EngineError::Other("Live Paint Merge: select a Live Paint group and the paths to add".into()))?;
check_live_paint_takes(d, roots)?;
let old = d.node(target).cloned().ok_or(EngineError::NoNode(target))?;
// The rows that join are children of the group already when Merge runs after a drag, and a joining
// path named like a face or an edge is not one of the group's parts.
let mut old_parts = old.clone();
if let Some(ch) = old_parts.children_mut() {
ch.retain(|c| !roots.contains(&c.id));
}
// Paint to carry over: (point inside face, paint) for faces that draw; edges are matched to the
// old edges below.
let keep_faces: Vec<(Point, Carried)> =
b::faces(&old).iter().filter(|f| draws(f)).filter_map(|f| Some((po::interior_point(f.path_data()?)?, Carried::of(f)))).collect();
let old_parts = old.clone();
b::faces(&old_parts).iter().filter(|f| draws(f)).filter_map(|f| Some((po::interior_point(f.path_data()?)?, Carried::of(f)))).collect();
let mut sources = source_nodes(&old);
// The objects drawn in the other Live Paint groups besides their parts stay in the merged group.
let mut others = vec![];
@@ -227,19 +270,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()
}
@@ -259,6 +305,189 @@ pub(crate) fn merge_drawn_in_isolation(s: &mut Session, g: NodeId) -> Result<boo
Ok(true)
}
/// Where a row sits for Live Paint: among the paths of a Live Paint group (in its sources group,
/// at any depth), directly in a Live Paint group, or neither.
#[derive(Clone, Copy, PartialEq, Eq)]
enum Spot {
Source(NodeId),
In(NodeId),
Outside,
}
/// The [`Spot`] of a row whose parent is `parent` (None: the top level).
fn spot_in(d: &Document, parent: Option<NodeId>) -> Spot {
let Some(p) = parent else { return Spot::Outside };
for x in d.ancestry(p).unwrap_or_default().into_iter().rev() {
let n = d.node(x);
if n.is_some_and(is_live_paint) {
return if x == p { Spot::In(x) } else { Spot::Outside };
}
if let Some(g) = d.parent_of(x)
&& d.node(g).filter(|n| is_live_paint(n)).and_then(b::sources).is_some_and(|s| s.id == x)
{
return Spot::Source(g);
}
}
Spot::Outside
}
/// The Live Paint groups that hold Live Paint group `g` among their paths (in their sources group,
/// at any depth), innermost first.
fn enclosing_live_paints(d: &Document, g: NodeId) -> Vec<NodeId> {
let mut out = vec![];
let mut at = g;
while let Spot::Source(o) = spot_in(d, d.parent_of(at)) {
if out.contains(&o) {
break;
}
out.push(o);
at = o;
}
out
}
/// What moving rows in the Layers panel (`layer.move`, `node.move`) does to Live Paint groups.
/// Rows that go into a Live Paint group from elsewhere are added to it as `livePaint.merge` adds
/// paths. Rows that go into or leave a group's paths (its sources group) change those paths, and
/// the group's faces and edges are made again from them, keeping the paint of the faces and edges
/// that stay, and so are those of every Live Paint group that holds a changed group among its
/// paths. Rows moved within one group's paths, or among a group's own children, change no faces.
pub(crate) struct LivePaintMove {
/// The Live Paint group the rows go into, and for each row whether it joins the group's paths.
join: Option<(NodeId, Vec<bool>)>,
/// The Live Paint group the rows go among the children of, with its sources group as it is
/// before the move.
keep_sources: Option<(NodeId, NodeId)>,
/// The Live Paint groups whose paths change.
rebuild: Vec<NodeId>,
}
impl LivePaintMove {
/// Plan moving `rows` (with `copy`, copies of them) into `parent`, before anything changes.
/// Refuses rows Live Paint can't take ([`b::live_paint_takes`]) that would go among a group's
/// paths, with the message Make and Merge give.
pub(crate) fn plan(d: &Document, rows: &[NodeId], parent: Option<NodeId>, copy: bool) -> Result<Self> {
let to = spot_in(d, parent);
let from: Vec<Spot> = rows.iter().map(|r| if copy { Spot::Outside } else { spot_in(d, d.parent_of(*r)) }).collect();
let mut rebuild = vec![];
for f in &from {
if let Spot::Source(g) = *f
&& *f != to
&& !rebuild.contains(&g)
{
rebuild.push(g);
}
}
if let Spot::Source(g) = to
&& from.iter().any(|f| *f != to)
&& !rebuild.contains(&g)
{
rebuild.push(g);
}
let entering: Vec<NodeId> = rows.iter().zip(&from).filter(|(_, f)| **f != to).map(|(r, _)| *r).collect();
let join = match to {
Spot::In(g) if !entering.is_empty() => Some((g, from.iter().map(|f| *f != to).collect())),
_ => None,
};
if to != Spot::Outside {
check_live_paint_takes(d, &entering)?;
}
let keep_sources = match to {
Spot::In(g) => d.node(g).and_then(b::sources).map(|s| (g, s.id)),
_ => None,
};
Ok(Self { join, keep_sources, rebuild })
}
/// Whether rows join a Live Paint group, which makes the move a "Merge Live Paint" step.
pub(crate) fn joins(&self) -> bool {
self.join.is_some()
}
/// After the rows were moved, now `moved` (in the order [`LivePaintMove::plan`] took them),
/// make the faces and edges of the groups whose paths changed again, and add the rows that
/// joined a group to it. → `moved` with the joined rows replaced by their group, once, and
/// without the faces and edges that were made again.
pub(crate) fn finish(self, d: &mut Document, sel: &mut Selection, moved: &[NodeId]) -> Result<Vec<NodeId>> {
// A moved object named like the sources group may now sit before it, where a lookup by name
// finds the object first. The group's own sources group goes back in front.
if let Some((g, src)) = self.keep_sources {
let ch = d.children_mut(Some(g))?;
if let Some(at) = ch.iter().position(|c| c.id == src)
&& ch[..at].iter().any(|c| c.name.as_deref() == Some(SOURCES_NAME))
{
let s = ch.remove(at);
ch.insert(0, s);
}
}
if self.join.is_none() && self.rebuild.is_empty() {
return Ok(moved.to_vec());
}
// The group the rows join is made again by the merge below, from its paths as they are now
// and with the paint of its faces and edges as they were before the move.
let join_group = self.join.as_ref().map(|(g, _)| *g);
// A Live Paint group among another group's paths gives that group its faces and edges, so
// the groups holding a changed group among their paths are made again too, innermost first.
let mut groups: Vec<NodeId> = vec![];
for g in self.rebuild.iter().copied().chain(join_group) {
for x in std::iter::once(g).chain(enclosing_live_paints(d, g)) {
if !groups.contains(&x) {
groups.push(x);
}
}
}
groups.sort_by_cached_key(|g| std::cmp::Reverse(d.ancestry(*g).map_or(0, |a| a.len())));
let joined: Vec<NodeId> = match &self.join {
Some((_, mask)) => moved.iter().zip(mask).filter(|(_, j)| **j).map(|(r, _)| *r).collect(),
None => vec![],
};
for g in groups {
if Some(g) == join_group {
let roots: Vec<NodeId> = std::iter::once(g).chain(joined.iter().copied()).collect();
merge_live(d, sel, &roots)?;
} else if d.node(g).is_some() {
rebuild_paths(d, g)?;
}
}
let Some((g, mask)) = self.join else { return Ok(moved.iter().copied().filter(|r| d.node(*r).is_some()).collect()) };
// `moved` holds each row once, so only the group can come twice. Faces and edges of the
// group moved along with the joining rows were made again, so they are left out.
let mut out = vec![];
let mut listed = false;
for (r, j) in moved.iter().zip(&mask) {
if *j {
if !listed {
out.push(g);
listed = true;
}
} else if d.node(*r).is_some() {
out.push(*r);
}
}
Ok(out)
}
}
/// Make Live Paint group `g`'s faces and edges again from the paths its sources group holds now,
/// with its Gap Options, carrying over the paint of the faces and edges that stay. With no path
/// left, the group keeps its sources group and its other children, and has no faces or edges.
fn rebuild_paths(d: &mut Document, g: NodeId) -> Result<()> {
let old = d.node(g).cloned().ok_or(EngineError::NoNode(g))?;
let sources = source_nodes(&old);
let mut n = old.clone();
if source_shapes(&sources).0.is_empty() {
let src = b::sources(&old).cloned().ok_or(EngineError::NoNode(g))?;
set_parts(&mut n, vec![src], &[]);
} else {
let (children, _, _) = build_children(d, sources, old.gap_options().max_gap())?;
set_parts(&mut n, children, &[]);
repaint_from(&mut n, &old);
}
let mut changed = Beside::replacing(d, &[g]);
changed.put(d, g, vec![n])?;
changed.finish(d)
}
fn live_targets(s: &Session, p: &Value) -> Result<Vec<NodeId>> {
let d = &s.doc()?.doc;
let ids = root_ids(s, p)?;
+1
View File
@@ -1611,6 +1611,7 @@ fn paste_clip(s: &mut Session, p: &Value, mode: PasteMode, clip: &Clipboard, cho
}
} else {
super::object::keep_pixel_aligned(&mut c, sc);
super::buildcmds::clear_part_name(d, par, &mut c);
new_ids.push(d.insert(par, idx, c)?);
}
}
+22 -5
View File
@@ -13,6 +13,7 @@ use serde_json::{Value, json};
use vectorcraft_doc::{Artboard, ArtboardSide, Document, LAYER_COLORS, LayerColor, Node, NodeId, NodeKind, Scaling};
use vectorcraft_geom::{Affine, Rect};
use super::buildcmds::LivePaintMove;
use super::{
CommandSpec, Result, Session, bad, bool_or, check_numbers, check_switches, checked_id, checked_ids_param, checked_node, checked_nodes_param, cmd,
color_value, f64_or, has_doc, has_selection, ids_param, index, object_param, ok, str_param, switch_or,
@@ -83,7 +84,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Layer Options…",
["Window", "Layers"],
None,
"{ids?|id? (default: the highlighted rows, else the current layer), name? (with prefs.identifyObjectsBy xmlId: a valid XML ID, stored as the object name), visible?, locked?, template?, printable?, preview?, dimImages?: 0..100|false, color?: index 0..26|\"#rrggbb\"|preset name (a hex color with an alpha part, #rrggbbaa or #rgba, is an error)} Layer Options; rows that are not layers take name, visible and locked, and `ids` may name ruler guides (their `guide.list` id), which hide or lock on their own. Template on also locks the layer and dims its images to 50% (unless given); off unlocks it and stops dimming. One undo step",
"{ids?|id? (default: the highlighted rows, else the current layer), name? (with prefs.identifyObjectsBy xmlId: a valid XML ID, stored as the object name), visible?, locked?, template?, printable?, preview?, dimImages?: 0..100|false, color?: index 0..26|\"#rrggbb\"|preset name (a hex color with an alpha part, #rrggbbaa or #rgba, is an error)} Layer Options; rows that are not layers take name, visible and locked, and `ids` may name ruler guides (their `guide.list` id), which hide or lock on their own. Template on also locks the layer and dims its images to 50% (unless given); off unlocks it and stops dimming. A path directly in a Live Paint group can't take the name Face or Edge, which name the group's faces and edges, unless it has it already. One undo step",
has_doc,
set_props
),
@@ -110,7 +111,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Move Rows",
[],
None,
"{ids|id, target, place?: \"above\"|\"below\"|\"inside\" (default inside), copy?: bool} drag rows in the Layers panel: above or below the target row (beside it, in its layer or group), or inside a layer, group or Intertwine group (on top of its contents). Layers go only in layers or at the top level, objects in layers, groups and Intertwine groups; an object placed beside a top-level layer goes inside it. An object placed in an Intertwine group becomes a member drawn in its row's order, with no arranged areas, and one placed in a group that is a member becomes part of that member; one that is or holds an Intertwine group, a Repeat, a graph or a Live Paint group is refused. A member moved out of its Intertwine group drops its arranged areas, and a group left with one member is replaced by that member, or becomes a plain group of it when the group has an opacity, blending, appearance, mask, lock or hidden state of its own (with no member, it is removed). A row never goes into itself; a locked layer or group takes nothing. `copy` (Alt-drag) moves copies, which may also go above or below a row they copy (the target among `ids`). Every selected object left hidden or locked, such as one moved into a hidden layer or group, is deselected (the key object too). One undo step → {ids}",
"{ids|id, target, place?: \"above\"|\"below\"|\"inside\" (default inside), copy?: bool} drag rows in the Layers panel: above or below the target row (beside it, in its layer or group), or inside a layer, group or Intertwine group (on top of its contents). Layers go only in layers or at the top level, objects in layers, groups and Intertwine groups; an object placed beside a top-level layer goes inside it. An object placed in an Intertwine group becomes a member drawn in its row's order, with no arranged areas, and one placed in a group that is a member becomes part of that member; one that is or holds an Intertwine group, a Repeat, a graph or a Live Paint group is refused. A member moved out of its Intertwine group drops its arranged areas, and a group left with one member is replaced by that member, or becomes a plain group of it when the group has an opacity, blending, appearance, mask, lock or hidden state of its own (with no member, it is removed). A row never goes into itself; a locked layer or group takes nothing. `copy` (Alt-drag) moves copies, which may also go above or below a row they copy (the target among `ids`). A row that goes into a Live Paint group from elsewhere joins its paths as livePaint.merge adds them, and the group is selected (paths, compound paths, groups of them and Live Paint groups; anything else is refused and nothing moves); a row that goes into or leaves a Live Paint group's paths makes the group's faces and edges again, keeping the paint of those that stay. Every selected object left hidden or locked, such as one moved into a hidden layer or group, is deselected (the key object too). One undo step → {ids} (a row that joined a Live Paint group is listed as the group)",
has_doc,
move_rows
),
@@ -119,7 +120,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Reorder",
[],
None,
"{id, parent?: id (null = top level), index} put a row at `index` (0 = bottom) of `parent` (layers only at the top level or in layers; an Intertwine group takes and gives up members as layer.move does), deselecting every selected object left hidden or locked (the key object too)",
"{id, parent?: id (null = top level), index} put a row at `index` (0 = bottom) of `parent` (layers only at the top level or in layers; an Intertwine group takes and gives up members as layer.move does), deselecting every selected object left hidden or locked (the key object too); a Live Paint group or its paths take a row as layer.move does",
has_doc,
move_node
),
@@ -651,6 +652,10 @@ fn set_props(s: &mut Session, p: &Value) -> Result<Value> {
if ids.is_empty() {
return Err(bad(C, "no rows"));
}
if let Some(v) = str_param(p, "name").filter(|v| !v.trim().is_empty()) {
let name = if xml_id { vectorcraft_doc::xml_id::to_object_name(v) } else { v.to_string() };
super::buildcmds::check_part_name(&s.doc()?.doc, &ids, &name)?;
}
s.edit("Layer Options", |d, sel| {
for id in &ids {
apply_options(d.node_mut(*id).ok_or(EngineError::NoNode(*id))?, p, xml_id);
@@ -807,7 +812,15 @@ fn move_rows(s: &mut Session, p: &Value) -> Result<Value> {
if parent.is_some_and(|p| locked_within(d, p)) {
return Err(EngineError::Other("the layer or group is locked".into()));
}
let label = if copy { "Duplicate Rows" } else { "Move Rows" };
// Rows that go into a Live Paint group join its paths, as Live Paint › Merge adds them.
let live_paint = LivePaintMove::plan(d, &ids, parent, copy)?;
let label = if live_paint.joins() {
"Merge Live Paint"
} else if copy {
"Duplicate Rows"
} else {
"Move Rows"
};
// Where each moved row comes from (a copy has a new id, so it comes from nowhere), and the
// Intertwine groups it leaves.
let from: std::collections::HashMap<NodeId, Option<NodeId>> = ids.iter().map(|i| (*i, d.parent_of(*i))).collect();
@@ -848,6 +861,7 @@ fn move_rows(s: &mut Session, p: &Value) -> Result<Value> {
}
let placed: Vec<(NodeId, Option<NodeId>)> = out.iter().map(|o| (*o, from.get(o).copied().flatten())).collect();
super::intertwine::settle_members(d, &placed, &left)?;
let out = live_paint.finish(d, sel, &out)?;
sel.prune(d);
sel.deselect_uneditable(d);
Ok(out)
@@ -870,11 +884,14 @@ fn move_node(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(what) = super::intertwine::refused_in(d, parent, n) {
return Err(bad(C, format!("{what} can't be intertwined")));
}
let live_paint = LivePaintMove::plan(d, &[id], parent, false)?;
let label = if live_paint.joins() { "Merge Live Paint" } else { "Reorder" };
let from = d.parent_of(id);
let left = super::intertwine::groups_of(d, &[id]);
s.edit("Reorder", |d, sel| {
s.edit(label, |d, sel| {
d.move_node(id, parent, index)?;
super::intertwine::settle_members(d, &[(id, from)], &left)?;
live_paint.finish(d, sel, &[id])?;
sel.prune(d);
sel.deselect_uneditable(d);
Ok(())
+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> {
+2 -2
View File
@@ -250,7 +250,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Exit Isolation Mode",
[],
None,
"{all?: bool (default false)} leave isolation mode; from an isolated sublayer, go up one level to its parent layer instead (the next call goes up again), unless all is true or the parent layer is hidden or locked; no undo step for the move up; while a symbol is edited, a group isolated in its art goes back to the symbol's layer first, with or without all; 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",
"{all?: bool (default false)} leave isolation mode; from an isolated sublayer, go up one level to its parent layer instead (the next call goes up again), unless all is true or the parent layer is hidden or locked; no undo step for the move up; while a symbol is edited, a group isolated in its art goes back to the symbol's layer first, with or without all; 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
),
@@ -259,7 +259,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Object Properties",
[],
None,
"{ids?|id?, name?, visible?, locked? (visible: false or locked: true deselects every selected object hidden or locked after the call, the key object included), opacity?: 0..100, blend?: \"Multiply\"…, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, data?: {key: \"value\" | null (removes it)} (the object's own data, SVG data-* attributes: {pivot: \"100,180\"} is data-pivot; document.node → attrs.data)}. On a path directly in a graph series, the graph also stores the object's opacity and blend mode, and on a series group the group's opacity, blend mode, isolate, knockout and knockoutShape (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's opacity and blend mode for every label or line of its kind",
"{ids?|id?, name?, visible?, locked? (visible: false or locked: true deselects every selected object hidden or locked after the call, the key object included), opacity?: 0..100, blend?: \"Multiply\"…, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, data?: {key: \"value\" | null (removes it)} (the object's own data, SVG data-* attributes: {pivot: \"100,180\"} is data-pivot; document.node → attrs.data)}. On a path directly in a graph series, the graph also stores the object's opacity and blend mode, and on a series group the group's opacity, blend mode, isolate, knockout and knockoutShape (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's opacity and blend mode for every label or line of its kind. A path directly in a Live Paint group can't take the name Face or Edge, which name the group's faces and edges, unless it has it already",
has_doc,
set_props
),
+3
View File
@@ -65,6 +65,9 @@ pub(super) fn set_props(s: &mut Session, p: &Value) -> Result<Value> {
})
};
let d = &s.doc()?.doc;
if let Some(v) = str_param(p, "name") {
crate::cmd::buildcmds::check_part_name(d, &ids, v)?;
}
// A graph keeps the object opacity and blend mode set on a mark of a series for the whole series, and set on a label
// for its kind of label, so a value a mark or label already has still replaces the one another left on the graph.
let transparency = opacity.is_some() || blend.is_some();
+376
View File
@@ -5027,6 +5027,73 @@ fn live_paint_does_not_count_art_named_like_its_parts() {
}
}
/// A path drawn in an isolated Live Paint group can't be named Face or Edge, the names of the
/// group's faces and edges: `object.setProps` and `layer.setProps` return an error and rename
/// nothing, so Gap Options and a path dragged into the group keep the path. A face keeps its name.
#[test]
fn live_paint_refuses_part_names_for_paths_drawn_in_it() {
use vectorcraft_tools::builder::{EDGE_NAME, FACE_NAME, faces};
let mut s = session();
let g = live(&mut s);
let face = faces(&node(&s, g))[0].id;
s.execute("object.isolate", &json!({"id": g.0})).unwrap();
let a = line_across(&mut s, 50.0);
// Hidden, the path stays in the group as drawn when isolation mode ends.
s.execute("object.setProps", &json!({"id": a.0, "visible": false})).unwrap();
let before = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len());
for name in [FACE_NAME, EDGE_NAME] {
let calls = [
("object.setProps", json!({"id": a.0, "name": name})),
("layer.setProps", json!({"id": a.0, "name": name})),
("layer.setProps", json!({"ids": [face.0, a.0], "name": name})),
];
for (c, p) in calls {
let err = s.execute(c, &p).unwrap_err().to_string();
assert!(err.contains("give the path another name"), "{c} {p}: {err}");
}
}
assert!(s.doc().unwrap().doc == before.0, "nothing was renamed");
assert_eq!(s.doc().unwrap().history.undo.len(), before.1);
s.execute("layer.setProps", &json!({"id": face.0, "name": FACE_NAME})).unwrap();
s.execute("object.exitIsolation", &json!({})).unwrap();
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g), "the hidden path stays in the group");
s.execute("livePaint.gapOptions", &json!({"ids": [g.0], "detect": true})).unwrap();
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g), "Gap Options keeps the path");
let b = line_to_right_face(&mut s, 30.0);
s.execute("layer.move", &json!({"ids": [b.0], "target": g.0, "place": "inside"})).unwrap();
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g), "a path dragged in keeps it");
assert_eq!(faces(&node(&s, g)).len(), 5);
}
/// A path pasted into an isolated Live Paint group under the name of a face or an edge loses the
/// name, so Gap Options keeps it and it joins the group's paths when isolation mode ends.
#[test]
fn live_paint_paste_clears_part_names() {
use vectorcraft_tools::builder::{EDGE_NAME, FACE_NAME, faces, sources};
for name in [FACE_NAME, EDGE_NAME] {
let mut s = session();
let g = live(&mut s);
let r = rect(&mut s, 20.0, 40.0, 60.0, 20.0);
s.execute("object.setProps", &json!({"id": r.0, "name": name})).unwrap();
s.execute("select.set", &json!({"ids": [r.0]})).unwrap();
s.execute("edit.copy", &json!({})).unwrap();
s.execute("object.isolate", &json!({"id": g.0})).unwrap();
s.execute("edit.pasteInPlace", &json!({})).unwrap();
let pasted = s.doc().unwrap().selection.objects.clone();
assert_eq!(pasted.len(), 1);
let d = &s.doc().unwrap().doc;
assert_eq!(d.parent_of(pasted[0]), Some(g), "{name}: the paste goes into the group");
assert_eq!(d.node(pasted[0]).unwrap().name, None, "{name}: the paste loses the name");
assert_eq!(d.node(r).unwrap().name.as_deref(), Some(name), "the path outside keeps its name");
s.execute("livePaint.gapOptions", &json!({"ids": [g.0], "detect": true})).unwrap();
assert_eq!(s.doc().unwrap().doc.parent_of(pasted[0]), Some(g), "{name}: Gap Options keeps the paste");
s.execute("object.exitIsolation", &json!({})).unwrap();
let n = node(&s, g);
assert_eq!(s.doc().unwrap().doc.parent_of(pasted[0]), Some(sources(&n).unwrap().id), "{name}: the paste joined");
assert!(faces(&n).len() > 3);
}
}
/// 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.
@@ -5098,6 +5165,315 @@ 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();
NodeId(r["id"].as_u64().unwrap())
}
fn undo_label(s: &Session) -> Option<String> {
s.doc().unwrap().history.undo.last().map(|e| e.label.clone())
}
/// Paths dragged into a Live Paint group in the Layers panel join its paths as Live Paint › Merge
/// adds them: they go among its sources and cut the faces they cross, a painted face they do not
/// cross keeps its fill, and the drop is one "Merge Live Paint" undo step that selects the group.
#[test]
fn layers_drag_adds_paths_to_a_live_paint_group() {
use vectorcraft_tools::builder::{face_at, faces, sources};
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
let mut s = session();
let g = live(&mut s);
s.execute("livePaint.fill", &json!({"group": g.0, "point": [125, 50], "color": "#00ff00"})).unwrap();
let layer = s.doc().unwrap().doc.parent_of(g);
let (a, b) = (line_to_right_face(&mut s, 30.0), line_to_right_face(&mut s, 70.0));
assert_eq!(s.doc().unwrap().doc.parent_of(a), layer);
let steps = s.doc().unwrap().history.undo.len();
let r = s.execute("layer.move", &json!({"ids": [a.0, b.0], "target": g.0, "place": "inside"})).unwrap();
assert_eq!(r["ids"], json!([g.0]), "the rows that joined are listed as the group");
let d = s.doc().unwrap();
assert_eq!(d.history.undo.len(), steps + 1, "both paths join in one undo step");
assert_eq!(undo_label(&s).as_deref(), Some("Merge Live Paint"));
assert_eq!(s.doc().unwrap().selection.objects, vec![g]);
let n = node(&s, g);
let src = sources(&n).unwrap();
assert_eq!(src.children().unwrap().len(), 4);
for id in [a, b] {
assert_eq!(s.doc().unwrap().doc.parent_of(id), Some(src.id), "{id} joined the sources");
}
assert_eq!(faces(&n).len(), 7, "two lines cut each of the two faces they cross in three");
assert_eq!(face_at(&n, Point::new(125.0, 50.0)).unwrap().appearance.fill_paint(), green, "the face the lines do not cross keeps its fill");
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(faces(&node(&s, g)).len(), 3);
for id in [a, b] {
assert_eq!(s.doc().unwrap().doc.parent_of(id), layer, "Undo puts {id} back where it was");
}
s.execute("edit.redo", &json!({})).unwrap();
assert_eq!(faces(&node(&s, g)).len(), 7);
}
/// A path named like a Live Paint group's sources group joins the group when it is dragged in, in
/// front of the sources group or behind it: the group keeps its own sources group and the path
/// goes among its paths.
#[test]
fn layers_drag_of_a_path_named_like_the_sources_group_joins_a_live_paint_group() {
use vectorcraft_tools::builder::{SOURCES_NAME, faces, sources};
for index in [0, 99] {
let mut s = session();
let g = live(&mut s);
let a = line_to_right_face(&mut s, 30.0);
s.execute("object.setProps", &json!({"id": a.0, "name": SOURCES_NAME})).unwrap();
s.execute("node.move", &json!({"id": a.0, "parent": g.0, "index": index})).unwrap();
assert_eq!(undo_label(&s).as_deref(), Some("Merge Live Paint"), "index {index}");
let n = node(&s, g);
let src = sources(&n).unwrap();
assert!(src.children().is_some(), "index {index}: the sources group is a group");
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(src.id), "index {index}: the path joined the sources");
assert_eq!(faces(&n).len(), 5, "index {index}");
}
}
/// An object drawn in a Live Paint group and named like its sources group can be moved ahead of the
/// sources group: the group keeps its own sources group and stays a Live Paint group.
#[test]
fn layers_reorder_of_an_object_named_like_the_sources_group_keeps_the_live_paint_group() {
use vectorcraft_tools::builder::{SOURCES_NAME, is_live_paint, sources};
let mut s = session();
let g = live(&mut s);
let real = sources(&node(&s, g)).unwrap().id;
s.execute("object.isolate", &json!({"id": g.0})).unwrap();
let a = line_across(&mut s, 50.0);
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g));
s.execute("object.setProps", &json!({"id": a.0, "name": SOURCES_NAME})).unwrap();
s.execute("node.move", &json!({"id": a.0, "parent": g.0, "index": 0})).unwrap();
let n = node(&s, g);
assert!(is_live_paint(&n));
assert_eq!(sources(&n).unwrap().id, real);
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(g), "the object stays where it was drawn");
}
/// A path named `Face` that is dragged into a Live Paint group is not one of its faces: the face it
/// covers keeps its own fill.
#[test]
fn layers_drag_of_a_path_named_face_does_not_repaint_the_group() {
use vectorcraft_tools::builder::{face_at, faces};
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
let mut s = session();
let g = live(&mut s);
s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "color": "#00ff00"})).unwrap();
let a = rect(&mut s, 0.0, 0.0, 50.0, 100.0);
set_fill(&mut s, a, Color::rgb(0.0, 0.0, 1.0));
s.execute("object.setProps", &json!({"id": a.0, "name": "Face"})).unwrap();
s.execute("node.move", &json!({"id": a.0, "parent": g.0, "index": 99})).unwrap();
let n = node(&s, g);
assert_eq!(faces(&n).len(), 3);
assert_eq!(face_at(&n, Point::new(25.0, 50.0)).unwrap().appearance.fill_paint(), green);
}
/// An Alt-drag into a Live Paint group adds a copy and leaves the path where it was; a drop above
/// one of the group's faces, and `node.move` into the group, add the path the same way.
#[test]
fn layers_drag_copy_and_drop_beside_a_part_add_to_a_live_paint_group() {
use vectorcraft_tools::builder::{faces, sources};
let mut s = session();
let g = live(&mut s);
let layer = s.doc().unwrap().doc.parent_of(g);
let a = line_to_right_face(&mut s, 30.0);
s.execute("layer.move", &json!({"ids": [a.0], "target": g.0, "copy": true})).unwrap();
assert_eq!(s.doc().unwrap().doc.parent_of(a), layer, "the path itself stays");
let n = node(&s, g);
assert_eq!(faces(&n).len(), 5);
let src = sources(&n).unwrap().children().unwrap().clone();
assert_eq!(src.len(), 3);
assert!(src.iter().all(|c| c.id != a), "a copy joined");
let (face, other_face) = (faces(&n)[0].id, faces(&n)[1].id);
let b = line_to_right_face(&mut s, 70.0);
// A face dragged along is made again with the others, so only the group is listed.
let r = s.execute("layer.move", &json!({"ids": [b.0, other_face.0], "target": face.0, "place": "above"})).unwrap();
assert_eq!(r["ids"], json!([g.0]));
assert_eq!(s.doc().unwrap().layer_rows, vec![g]);
let n = node(&s, g);
assert_eq!(s.doc().unwrap().doc.parent_of(b), Some(sources(&n).unwrap().id), "a drop beside a face joins");
assert_eq!(faces(&n).len(), 7);
let c = line_to_right_face(&mut s, 50.0);
s.execute("node.move", &json!({"id": c.0, "parent": g.0, "index": 0})).unwrap();
assert_eq!(undo_label(&s).as_deref(), Some("Merge Live Paint"));
let n = node(&s, g);
assert_eq!(s.doc().unwrap().doc.parent_of(c), Some(sources(&n).unwrap().id), "node.move into the group joins");
assert_eq!(faces(&n).len(), 9);
}
/// Dragging type, or type with a path, into a Live Paint group is refused with Make's message and
/// moves nothing, as Merge refuses it; a drop beside the group is an ordinary move.
#[test]
fn layers_drag_refuses_type_into_a_live_paint_group() {
use vectorcraft_tools::builder::faces;
let mut s = session();
let g = live(&mut s);
let layer = s.doc().unwrap().doc.parent_of(g);
let a = line_to_right_face(&mut s, 30.0);
let text = NodeId(s.execute("text.create", &json!({"x": 20, "y": 20, "text": "Hi"})).unwrap()["id"].as_u64().unwrap());
let before = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len());
for p in [json!({"ids": [a.0, text.0], "target": g.0}), json!({"ids": [text.0], "target": g.0, "copy": true})] {
let err = s.execute("layer.move", &p).unwrap_err().to_string();
assert!(err.contains("Live Paint takes paths and compound paths"), "{err}");
}
assert!(s.execute("node.move", &json!({"id": text.0, "parent": g.0, "index": 0})).is_err());
assert!(s.doc().unwrap().doc == before.0, "nothing moved");
assert_eq!(s.doc().unwrap().history.undo.len(), before.1);
s.execute("layer.move", &json!({"ids": [a.0, text.0], "target": g.0, "place": "above"})).unwrap();
assert_eq!(undo_label(&s).as_deref(), Some("Move Rows"));
assert_eq!(s.doc().unwrap().doc.parent_of(text), layer);
assert_eq!(faces(&node(&s, g)).len(), 3);
}
/// A path dragged out of a Live Paint group's sources leaves its faces and edges: the group makes
/// them again from the paths left, and with none left it has no faces until a path joins it again.
/// Reordering the sources, or the group's own faces, makes nothing again.
#[test]
fn layers_drag_out_of_a_live_paint_group_makes_its_faces_again() {
use vectorcraft_tools::builder::{faces, sources};
let mut s = session();
let g = live(&mut s);
let layer = s.doc().unwrap().doc.parent_of(g).unwrap();
let n = node(&s, g);
let src: Vec<NodeId> = sources(&n).unwrap().children().unwrap().iter().map(|c| c.id).collect();
let face_ids: Vec<NodeId> = faces(&n).iter().map(|f| f.id).collect();
s.execute("layer.move", &json!({"ids": [src[0].0], "target": src[1].0, "place": "above"})).unwrap();
s.execute("layer.move", &json!({"ids": [face_ids[0].0], "target": face_ids[2].0, "place": "above"})).unwrap();
let n = node(&s, g);
assert_eq!(sources(&n).unwrap().children().unwrap().len(), 2, "a reorder keeps the sources");
let mut now: Vec<NodeId> = faces(&n).iter().map(|f| f.id).collect();
now.sort();
let mut was = face_ids.clone();
was.sort();
assert_eq!(now, was, "and the faces");
s.execute("layer.move", &json!({"ids": [src[0].0], "target": layer.0})).unwrap();
assert_eq!(undo_label(&s).as_deref(), Some("Move Rows"));
let n = node(&s, g);
assert_eq!(s.doc().unwrap().doc.parent_of(src[0]), Some(layer));
assert_eq!(sources(&n).unwrap().children().unwrap().len(), 1);
assert_eq!(faces(&n).len(), 1, "one rectangle left");
s.execute("node.move", &json!({"id": src[1].0, "parent": layer.0, "index": 0})).unwrap();
let n = node(&s, g);
assert!(vectorcraft_tools::builder::is_live_paint(&n), "the group stays a Live Paint group");
assert!(sources(&n).unwrap().children().unwrap().is_empty());
assert!(faces(&n).is_empty() && vectorcraft_tools::builder::edges(&n).is_empty());
s.execute("layer.move", &json!({"ids": [src[0].0], "target": g.0})).unwrap();
assert_eq!(faces(&node(&s, g)).len(), 1, "a path joins the empty group");
s.execute("edit.undo", &json!({})).unwrap();
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(faces(&node(&s, g)).len(), 1);
}
/// A path dragged from a Live Paint group's sources into the group itself stays among its paths,
/// and the faces it bounds keep their paint, also when it is the group's only path.
#[test]
fn layers_drag_a_source_path_into_its_own_live_paint_group_keeps_the_paint() {
use vectorcraft_tools::builder::{face_at, faces, sources};
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
let blue = Paint::solid(Color::from_hex("#0000ff").unwrap());
let mut s = session();
let g = live(&mut s);
let layer = s.doc().unwrap().doc.parent_of(g).unwrap();
s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "color": "#00ff00"})).unwrap();
let src: Vec<NodeId> = sources(&node(&s, g)).unwrap().children().unwrap().iter().map(|c| c.id).collect();
s.execute("layer.move", &json!({"ids": [src[0].0], "target": g.0, "place": "inside"})).unwrap();
let n = node(&s, g);
assert_eq!(s.doc().unwrap().doc.parent_of(src[0]), Some(sources(&n).unwrap().id), "the path stays among the group's paths");
assert_eq!(faces(&n).len(), 3);
assert_eq!(face_at(&n, Point::new(25.0, 50.0)).unwrap().appearance.fill_paint(), green, "the face it bounds keeps its fill");
s.execute("layer.move", &json!({"ids": [src[1].0], "target": layer.0})).unwrap();
s.execute("livePaint.fill", &json!({"group": g.0, "point": [50, 50], "color": "#0000ff"})).unwrap();
s.execute("layer.move", &json!({"ids": [src[0].0], "target": g.0, "place": "inside"})).unwrap();
let n = node(&s, g);
assert_eq!(faces(&n).len(), 1);
assert_eq!(face_at(&n, Point::new(50.0, 50.0)).unwrap().appearance.fill_paint(), blue, "the only path's face keeps its fill");
}
/// A Live Paint group among another Live Paint group's paths gives it faces and edges: a path
/// dragged into or out of the inner group's paths, or from the outer group's paths into the inner
/// group's, makes the inner group's faces and edges again and then the outer group's.
#[test]
fn layers_drag_into_a_nested_live_paint_group_makes_the_outer_group_again() {
use vectorcraft_tools::builder::{faces, sources};
let mut s = session();
let outer = live(&mut s);
let inner = live(&mut s);
let layer = s.doc().unwrap().doc.parent_of(outer).unwrap();
let first_source = |s: &Session, g: NodeId| sources(&node(s, g)).unwrap().children().unwrap()[0].id;
let into = |s: &mut Session, row: NodeId, g: NodeId| {
let target = first_source(s, g);
s.execute("layer.move", &json!({"ids": [row.0], "target": target.0, "place": "above"})).unwrap();
};
into(&mut s, inner, outer);
assert_eq!(s.doc().unwrap().doc.parent_of(inner), Some(sources(&node(&s, outer)).unwrap().id));
let plain = faces(&node(&s, outer)).len();
let a = line_to_right_face(&mut s, 30.0);
into(&mut s, a, inner);
assert_eq!(faces(&node(&s, inner)).len(), 5);
let cut = faces(&node(&s, outer)).len();
assert!(cut > plain, "a path joining the inner group cuts the outer group's faces: {cut} faces, {plain} before");
s.execute("layer.move", &json!({"ids": [a.0], "target": layer.0})).unwrap();
assert_eq!(faces(&node(&s, inner)).len(), 3);
assert_eq!(faces(&node(&s, outer)).len(), plain, "a path leaving the inner group leaves the outer group's faces");
into(&mut s, a, outer);
assert_eq!(faces(&node(&s, outer)).len(), cut);
into(&mut s, a, inner);
assert_eq!(s.doc().unwrap().doc.parent_of(a), Some(sources(&node(&s, inner)).unwrap().id));
assert_eq!(faces(&node(&s, inner)).len(), 5);
assert_eq!(faces(&node(&s, outer)).len(), cut, "the outer group is made after the inner one");
}
/// Give Live Paint group `g` a lock, hidden state, appearance, knockout, opacity mask and
/// graphic style link, and return it as it then is.
fn dress_live_group(s: &mut Session, g: NodeId) -> Node {