Symbols: Shift with Redefine Symbol keeps the art as ordinary art

Redefine Symbol chosen from the Symbols panel menu with Shift held now
updates the symbol and its instances from the selected art and leaves
that art as ordinary art, as the Edit symbols help page describes
(https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/edit-symbols.html).
Without Shift the art still becomes an instance.

- symbol.update takes keepArt (default false). With true the art keeps
  its ids, layer and stacking position and stays selected, apart from
  art that is hidden or locked, and the result's id is null. A keepArt
  that is not true or false is an error.
- Redefining the symbol being edited with keepArt still leaves symbol
  editing mode in the same undo step.

Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-11-17 11:51:44 -08:00
parent 999e538fd6
commit 3919a1a5df
7 changed files with 154 additions and 8 deletions
+1 -1
View File
@@ -256,7 +256,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Redefine Symbol",
[],
None,
"{name, ids?|id?} replace the symbol's art with the selection (instances update, keeping their appearance changes to the objects at paths the new art still has; the selection becomes an instance; a frame of threaded text in the selection leaves its thread with the text it shows, which the symbol's art holds; art that holds an instance of the symbol (opacity masks included), directly or through the symbols it nests, is refused) → {name, id}",
"{name, ids?|id?, keepArt?: false} replace the symbol's art with the selection (instances update, keeping their appearance changes to the objects at paths the new art still has; the selection becomes an instance, or with keepArt: true stays ordinary art where it is, still selected, and id is null; a frame of threaded text in the selection that becomes an instance leaves its thread with the text it shows, which the symbol's art holds; art that holds an instance of the symbol (opacity masks included), directly or through the symbols it nests, is refused) → {name, id}",
has_selection,
symbol_update
),
+17 -2
View File
@@ -612,6 +612,8 @@ pub(super) fn symbol_update(s: &mut Session, p: &Value) -> Result<Value> {
}
// Redefining the symbol being edited leaves symbol editing mode in the same step.
let session = s.doc()?.doc.symbol_edit.clone().filter(|e| e.symbol == name);
// `keepArt` leaves the art as ordinary art instead of replacing it with an instance.
let keep_art = switch_or(p, "keepArt", false, C)?;
if session.is_some() {
crate::cmd::settle_interaction(s)?;
s.end_text_edit();
@@ -633,6 +635,12 @@ pub(super) fn symbol_update(s: &mut Session, p: &Value) -> Result<Value> {
let (art, size, c) = normalize(art)?;
let old = natural_size(&s.doc()?.doc, &name);
let editing = session.is_some();
// The isolation the kept art is selected in: the one from before symbol editing mode when
// the step leaves it.
let iso = match &session {
Some(se) => se.back_isolation,
None => s.doc()?.isolation,
};
let id = s.edit("Redefine Symbol", |d, sel| {
if editing {
crate::cmd::symboledit::finish(d, sel);
@@ -651,15 +659,22 @@ pub(super) fn symbol_update(s: &mut Session, p: &Value) -> Result<Value> {
}
// Each instance keeps its appearance changes to the objects the new art still has.
fit_overrides(d, &instances);
if keep_art {
// The art stays where it is and stays selected, apart from art that is hidden or
// locked, in a hidden or locked group or layer, or on a locked artboard.
let locks = d.locked_artboards();
sel.set(ids.iter().copied().filter(|i| crate::cmd::select::is_selectable(d, iso, &locks, *i)));
return Ok(None);
}
let reg = d.symbol_registration(&name);
let id = instance_in_place(d, &ids, &name, place_xf(c + reg.offset_from_center(size.0, size.1), size, reg))?;
sel.set([id]);
Ok(id)
Ok(Some(id))
})?;
if let Some(se) = &session {
crate::cmd::symboledit::leave_editing(s, se)?;
}
Ok(json!({ "name": name, "id": id.0 }))
Ok(json!({ "name": name, "id": id.map(|i| i.0) }))
}
/// How many levels of nested instances Delete Symbol expands before it gives up.
+75
View File
@@ -1856,6 +1856,81 @@ fn break_link_then_update_redefines_all_instances() {
assert!((bounds(&s, other).center().x - 300.0).abs() < 1e-6);
}
/// Redefine Symbol with `keepArt: true` updates the symbol and its instances from the selection,
/// and the selected art stays ordinary art in its place, with its ids, still selected; the result
/// has no instance id. One undo step takes the definition back. Without `keepArt`, or with false,
/// the art becomes an instance.
#[test]
fn redefine_with_keep_art_leaves_the_art_as_ordinary_art() {
let mut s = session();
let (inst, name, _) = make_symbol(&mut s);
let a = rect(&mut s, 20.0, 200.0, 60.0, 30.0);
let b = rect(&mut s, 100.0, 200.0, 40.0, 50.0);
let spot = |s: &Session, id: NodeId| s.doc().unwrap().doc.position(id).map(|(p, i, _)| (p, i));
let before = (node(&s, a), node(&s, b), spot(&s, a), spot(&s, b));
let symbol_art = |s: &Session| s.doc().unwrap().doc.symbols.iter().find(|x| x.name == name).map(|x| x.art.clone()).unwrap();
let old_art = symbol_art(&s);
let steps = s.doc().unwrap().history.undo.len();
select(&mut s, &[a, b]);
let r = s.execute("symbol.update", &json!({"name": name, "keepArt": true})).unwrap();
assert_eq!(r, json!({"name": name, "id": null}));
assert_eq!((node(&s, a), node(&s, b), spot(&s, a), spot(&s, b)), before, "the art is unchanged and in its place");
assert_eq!(s.doc().unwrap().selection.objects, vec![a, b], "the art stays selected");
let instances = |s: &Session| {
let mut n = 0;
s.doc().unwrap().doc.walk(|c| n += usize::from(matches!(c.kind, NodeKind::SymbolInstance { .. })));
n
};
assert_eq!(instances(&s), 1, "no new instance");
// The instance shows the new art: the 120 × 50 pair.
let w = bounds(&s, inst);
assert!((w.width() - 120.0).abs() < 1e-6 && (w.height() - 50.0).abs() < 1e-6, "{w:?}");
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(symbol_art(&s), old_art, "undo takes the definition back");
s.execute("edit.redo", &json!({})).unwrap();
assert!((bounds(&s, inst).width() - 120.0).abs() < 1e-6, "{:?}", bounds(&s, inst));
// false, like no keepArt, makes the art an instance.
for p in [json!({"name": name, "ids": [a.0], "keepArt": false}), json!({"name": name, "ids": [b.0]})] {
let r = s.execute("symbol.update", &p).unwrap();
let id = NodeId(r["id"].as_u64().expect("an instance id"));
assert!(matches!(node(&s, id).kind, NodeKind::SymbolInstance { .. }), "{p}");
assert_eq!(s.doc().unwrap().selection.objects, vec![id], "{p}");
}
assert!(s.doc().unwrap().doc.node(a).is_none() && s.doc().unwrap().doc.node(b).is_none());
}
/// Redefine Symbol with `keepArt: true` and explicit ids keeps the named art selected only where
/// it can be selected: locked or hidden art is left out. A `keepArt` that is not true or false is
/// refused, with no change and no undo step.
#[test]
fn redefine_with_keep_art_selects_only_selectable_art_and_refuses_a_bad_switch() {
let mut s = session();
let (_, name, _) = make_symbol(&mut s);
let a = rect(&mut s, 20.0, 200.0, 60.0, 30.0);
let locked = rect(&mut s, 100.0, 200.0, 40.0, 50.0);
let hidden = rect(&mut s, 200.0, 200.0, 40.0, 50.0);
{
let doc = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc);
doc.node_mut(locked).unwrap().locked = true;
doc.node_mut(hidden).unwrap().visible = false;
}
for bad in [json!("true"), json!(1), json!([true])] {
let before = s.doc().unwrap().doc.clone();
let steps = s.doc().unwrap().history.undo.len();
let e = s.execute("symbol.update", &json!({"name": name, "ids": [a.0], "keepArt": bad})).unwrap_err();
assert!(e.to_string().contains("`keepArt` must be true or false"), "{bad}: {e}");
assert!(std::sync::Arc::ptr_eq(&before, &s.doc().unwrap().doc), "{bad}: the document is unchanged");
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "{bad}: no undo step");
}
select(&mut s, &[]);
s.execute("symbol.update", &json!({"name": name, "ids": [a.0, locked.0, hidden.0], "keepArt": true})).unwrap();
assert_eq!(s.doc().unwrap().selection.objects, vec![a], "only the selectable art is selected");
for id in [a, locked, hidden] {
assert!(matches!(node(&s, id).kind, NodeKind::Path { .. }), "{id:?} stays ordinary art");
}
}
/// Redefine Symbol refuses art that holds an instance of the symbol it redefines, directly, in a
/// group, in an opacity mask, or through the art of another symbol it holds an instance of, and
/// then changes nothing and adds no undo step. An instance of an unrelated symbol still redefines
+22
View File
@@ -253,6 +253,28 @@ fn redefining_the_symbol_being_edited_leaves_symbol_editing_mode_in_the_same_ste
assert!(st.doc.symbol_edit.is_some());
}
/// Redefining the symbol being edited with `keepArt: true` also leaves symbol editing mode in the
/// same step; the art outside the editing layer stays ordinary art and stays selected, and the
/// art on the editing layer still can't redefine it.
#[test]
fn redefining_the_symbol_being_edited_with_keep_art_leaves_the_art_and_the_mode() {
let (mut s, first, second) = two_instances();
let other = id(&run(&mut s, "shape.rectangle", json!({"x": 10, "y": 200, "width": 30, "height": 30})));
let layer = NodeId(run(&mut s, "symbol.edit", json!({"id": first.0}))["layer"].as_u64().unwrap());
let e = s.execute("symbol.update", &json!({"name": "Box", "keepArt": true})).unwrap_err().to_string();
assert!(e.contains("can't hold an instance of itself"), "{e}");
let steps = s.doc().unwrap().history.undo.len();
let r = run(&mut s, "symbol.update", json!({"name": "Box", "ids": [other.0], "keepArt": true}));
assert!(r["id"].is_null(), "{r}");
let st = s.doc().unwrap();
assert!(st.doc.symbol_edit.is_none() && st.isolation.is_none() && st.doc.node(layer).is_none());
assert_eq!(st.history.undo.len(), steps + 1);
assert!(matches!(st.doc.node(other).map(|n| &n.kind), Some(NodeKind::Path { .. })), "the art stays ordinary art");
assert_eq!(st.selection.objects, vec![other], "the art stays selected");
assert!(is_instance(&s, first), "the instance editing was entered from is still an instance");
assert!(close(bounds(&s, second), Rect::new(285.0, 185.0, 315.0, 215.0)), "{:?}", bounds(&s, second));
}
#[test]
fn leaving_goes_back_to_the_isolation_before_and_undo_keeps_a_group_isolated_inside() {
let (mut s, first, _) = two_instances();