Symbols: Replace Symbol clears the old symbol's dynamic overrides

An override on a dynamic symbol instance names an object of its symbol's
art by path. Replace Symbol kept every override whose path the new
symbol's art also had, so a change made to one object of the old symbol
was applied to an unrelated object of the new one. An instance given a
different symbol now drops its overrides; an instance replaced with its
own symbol keeps them. Undo brings them back.
This commit is contained in:
dotCooCoo
2026-11-01 16:24:33 -08:00
parent 639c9d6ce9
commit 2adf5a9a61
5 changed files with 34 additions and 6 deletions
+1 -1
View File
@@ -247,7 +247,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Replace Symbol",
[],
None,
"{name, ids?|id?} swap the symbol of the selected instances (they keep their appearance changes to the objects at paths a dynamic new symbol's art has) → {ids}",
"{name, ids?|id?} swap the symbol of the selected instances (an instance given a different symbol drops its appearance changes; one given its own symbol keeps them) → {ids}",
has_selection,
symbol_replace
),
+8 -3
View File
@@ -590,14 +590,19 @@ pub(super) fn symbol_replace(s: &mut Session, p: &Value) -> Result<Value> {
s.edit("Replace Symbol", |d, _| {
let new = natural_size(d, &name);
for id in &ids {
let old = match d.node(*id).map(|n| &n.kind) {
Some(NodeKind::SymbolInstance { symbol, .. }) => natural_size(d, symbol),
let (old, other) = match d.node(*id).map(|n| &n.kind) {
Some(NodeKind::SymbolInstance { symbol, .. }) => (natural_size(d, symbol), *symbol != name),
_ => continue,
};
if let Some(NodeKind::SymbolInstance { symbol, xf }) = d.node_mut(*id).map(|n| &mut n.kind) {
let Some(n) = d.node_mut(*id) else { continue };
if let NodeKind::SymbolInstance { symbol, xf } = &mut n.kind {
*symbol = name.clone();
*xf *= Affine::scale_non_uniform(new.0 / old.0, new.1 / old.1);
}
// An override's path names an object of the old symbol's art.
if other && !n.extras().symbol_overrides.is_empty() {
n.extras_mut().symbol_overrides.clear();
}
}
fit_overrides(d, &ids);
Ok(())