Merge pull request #7182 from dotCooCoo/feat/objects-on-path-detach

Objects on Path: Detach takes the chosen object off the path
This commit is contained in:
BFlat
2026-11-14 00:51:59 +07:00
committed by GitHub
35 changed files with 412 additions and 7 deletions
+54 -2
View File
@@ -12,7 +12,8 @@
//! `object.objectsOnPath.selectMember` chooses one object of a selected group (its Select/Move
//! widget), and `object.objectsOnPath.moveMember` moves one object to another's place along the
//! path, the objects between it and that place each moving one place toward where it was; hidden
//! and locked objects keep their places.
//! and locked objects keep their places. `object.objectsOnPath.detach` takes one object out of its
//! group, just above it, and the others move up the path.
//!
//! After every edit, [`refresh`] puts the objects of each Objects on Path group that changed back
//! on its path: editing the path moves them, an object moved on its own goes back to its place,
@@ -21,7 +22,8 @@
//!
//! Behavior: <https://helpx.adobe.com/illustrator/using/objects-on-path.html> (the tool and
//! Object › Objects on Path › Attach; the order on the path, the attachment point, the distribution,
//! the objects squared to the path; Pivot and Rotate; path edits realign the objects; Expand).
//! the objects squared to the path; Pivot and Rotate; path edits realign the objects; Detach and
//! the objects that move up the path after it; Expand).
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
@@ -75,6 +77,15 @@ pub fn specs() -> Vec<CommandSpec> {
has_doc,
move_member
),
cmd!(
"object.objectsOnPath.detach",
"Detach Object from Path",
[],
None,
"{member?: id of an object of an Objects on Path group (default: the object chosen with the selected group's Select/Move widget); neither the object nor the group may be hidden or locked} take one object off the path, out of its group and just above the group in the Layers panel, where it stays as drawn and is selected alone. The group's other objects move up the path in their order: with Auto Space they spread evenly again, and a Space value and the start are kept. The group and its path stay, even with one object or none left → {group, member}",
has_doc,
detach
),
cmd!(
"object.objectsOnPath.expand",
"Expand",
@@ -383,6 +394,47 @@ fn move_member(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "group": g.0, "member": member.0, "index": index }))
}
// ---------- Detach ----------
/// The object chosen with the Select/Move widget of the one selected Objects on Path group.
fn chosen_member(s: &Session) -> Option<NodeId> {
let st = s.active()?;
match st.selection.objects[..] {
[_] => st.selection.on_path_member,
_ => None,
}
}
fn detach(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "object.objectsOnPath.detach";
const CHOOSE: &str = "choose the object to detach with its Select/Move widget";
let (g, member) = if p.get("member").is_none_or(Value::is_null) {
let chosen = chosen_member(s).ok_or_else(|| bad(C, CHOOSE))?;
let found = member_param(s, &json!({ "member": chosen.0 }), "member", C)?;
if s.active().is_none_or(|st| st.selection.objects[..] != [found.0]) {
return Err(bad(C, CHOOSE));
}
found
} else {
member_param(s, p, "member", C)?
};
// The object goes just above the group, in the group's parent, and keeps where it is drawn.
// When the group is itself an object on another group's path, the object goes above that
// group instead (and so on outward), so it does not join that path. The refresh after the edit
// removes it from the group's record and moves the others up the path.
s.edit("Detach Object from Path", |d, sel| {
let mut above = g;
while let Some(p) = d.parent_of(above).filter(|p| d.node(*p).is_some_and(is_objects_on_path)) {
above = p;
}
let (parent, index, _) = d.position(above).ok_or(EngineError::NoNode(above))?;
d.move_node(member, parent, index + 1)?;
sel.set([member]);
Ok(())
})?;
Ok(json!({ "group": g.0, "member": member.0 }))
}
// ---------- Expand ----------
fn expand(s: &mut Session, p: &Value) -> Result<Value> {
@@ -314,6 +314,7 @@ pub(super) const ALLOWED: &[&str] = &[
"object.move",
"object.nudge",
"object.objectsOnPath.attach",
"object.objectsOnPath.detach",
"object.objectsOnPath.expand",
"object.objectsOnPath.moveMember",
"object.objectsOnPath.options",