mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 14:49:18 +00:00
Symbols: Shift with New Symbol keeps the art as ordinary art
Making a new symbol from the selected art with Shift held now adds the symbol and leaves the art as ordinary art, as the Create a symbol section of the help page describes (https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=192). Without Shift the art still becomes an instance. - symbol.new takes keepArt (default false). With true the art keeps its ids, layer and stacking position and stays selected, apart from art that cannot be selected, frames of threaded text stay in their thread, and the result's id is null. A keepArt that is not true or false is an error. - The Symbols panel's New Symbol button and its New Symbol... menu item read Shift when clicked and carry it through Symbol Options' OK; Shift with Alt on the button makes the symbol at once and keeps the art. Art dragged onto the panel reads Shift as it is released. - ui.symbolOptions takes keepArt for a new symbol and refuses it when editing a symbol. Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
@@ -202,7 +202,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"New Symbol…",
|
||||
[],
|
||||
None,
|
||||
"{name?, ids?|id?, registration?: 0..8 (9-point grid, 4 = centre; Symbol Options › Registration), exportType?: movieClip (default)|graphic, nineSlice?: bool, nineSliceGuides?: array, type?: static (default)|dynamic (Symbol Options › Symbol Type), alignToPixelGrid?: bool (default false; Symbol Options › Align to Pixel Grid)} make a symbol from the selection and replace it with an instance; a frame of threaded text in the selection leaves its thread with the text it shows, which the symbol's art holds; nineSlice is Symbol Options › Enable Guides for 9-Slice Scaling, nineSliceGuides [left, top, right, bottom] as fractions of the natural size in from each edge, each -16..16 (below 0 or above 1 puts a guide outside the art), with left + right < 1 and top + bottom < 1 (default a quarter each); an instance of a symbol with guides keeps its corners' size when scaled, its edges stretch along their length and its center in both directions; alignToPixelGrid keeps the symbol's instances on the pixel grid as symbol.options describes → {name, id, registration, exportType, nineSlice, type, alignToPixelGrid}",
|
||||
"{name?, ids?|id?, registration?: 0..8 (9-point grid, 4 = centre; Symbol Options › Registration), exportType?: movieClip (default)|graphic, nineSlice?: bool, nineSliceGuides?: array, type?: static (default)|dynamic (Symbol Options › Symbol Type), alignToPixelGrid?: bool (default false; Symbol Options › Align to Pixel Grid), keepArt?: false} make a symbol from the selection and replace it with an instance, or with keepArt: true leave the selection as ordinary art where it is, still selected, with id 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; nineSlice is Symbol Options › Enable Guides for 9-Slice Scaling, nineSliceGuides [left, top, right, bottom] as fractions of the natural size in from each edge, each -16..16 (below 0 or above 1 puts a guide outside the art), with left + right < 1 and top + bottom < 1 (default a quarter each); an instance of a symbol with guides keeps its corners' size when scaled, its edges stretch along their length and its center in both directions; alignToPixelGrid keeps the symbol's instances on the pixel grid as symbol.options describes → {name, id, registration, exportType, nineSlice, type, alignToPixelGrid}",
|
||||
has_selection,
|
||||
symbol_new
|
||||
),
|
||||
|
||||
@@ -253,6 +253,9 @@ pub(super) fn symbol_new(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let nine = nine_slice_param(p, C, None)?.flatten();
|
||||
let dynamic = type_param(p, C)?.unwrap_or(false);
|
||||
let pixel = pixel_grid_param(p, C)?.unwrap_or(false);
|
||||
// `keepArt` leaves the art as ordinary art instead of replacing it with an instance.
|
||||
let keep_art = switch_or(p, "keepArt", false, C)?;
|
||||
let iso = s.doc()?.isolation;
|
||||
// Keep the art where it was: the geometric centre stays at `c`, whatever the registration is.
|
||||
let place = place_xf(c + reg.offset_from_center(size.0, size.1), size, reg);
|
||||
let id = s.edit("New Symbol", |d, sel| {
|
||||
@@ -264,13 +267,20 @@ pub(super) fn symbol_new(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
d.set_symbol_export_type(&name, export);
|
||||
d.set_symbol_nine_slice(&name, nine);
|
||||
d.set_symbol_pixel_aligned(&name, pixel);
|
||||
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 id = instance_in_place(d, &ids, &name, place)?;
|
||||
sel.set([id]);
|
||||
Ok(id)
|
||||
Ok(Some(id))
|
||||
})?;
|
||||
Ok(json!({
|
||||
"name": name,
|
||||
"id": id.0,
|
||||
"id": id.map(|i| i.0),
|
||||
"registration": reg.0,
|
||||
"exportType": export.id(),
|
||||
"nineSlice": nine.map_or(Value::Null, SymbolNineSlice::to_value),
|
||||
|
||||
@@ -1991,6 +1991,31 @@ fn frames_made_into_a_symbol_leave_their_thread_with_their_text() {
|
||||
}
|
||||
}
|
||||
|
||||
/// New Symbol and Redefine Symbol with `keepArt: true` on a frame of threaded text leave the
|
||||
/// thread as it was: every frame stays a frame of the thread with the text it holds, and the
|
||||
/// symbol's art holds a copy of the text the frame shows.
|
||||
#[test]
|
||||
fn frames_kept_as_art_by_a_new_or_redefined_symbol_stay_in_their_thread() {
|
||||
for command in ["symbol.new", "symbol.update"] {
|
||||
let (mut s, frames) = three_frames(&TEXT.repeat(4), 200.0);
|
||||
let shown = frames.map(|id| text(&s, id));
|
||||
let name = if command == "symbol.update" {
|
||||
let mark = new_id(s.execute("shape.rectangle", &json!({"x": 400, "y": 200, "width": 20, "height": 20})).unwrap());
|
||||
s.execute("select.set", &json!({"ids": [mark]})).unwrap();
|
||||
s.execute("symbol.new", &json!({"name": "Mark"})).unwrap();
|
||||
"Mark"
|
||||
} else {
|
||||
"Story"
|
||||
};
|
||||
s.execute("select.set", &json!({"ids": [frames[1]]})).unwrap();
|
||||
let r = s.execute(command, &json!({"name": name, "keepArt": true})).unwrap();
|
||||
assert!(r["id"].is_null(), "{command}: {r}");
|
||||
assert_eq!(threads(&s), [frames], "{command}: the thread is as it was");
|
||||
assert_eq!(frames.map(|id| text(&s, id)), shown, "{command}: each frame keeps its text");
|
||||
assert_eq!(symbol_texts(&s, name), [shown[1].clone()], "{command}: the symbol's art holds the text the frame shows");
|
||||
}
|
||||
}
|
||||
|
||||
/// A frame of a numbered thread pasted while an opacity mask is edited numbers from 1 in the
|
||||
/// mask art too.
|
||||
#[test]
|
||||
|
||||
@@ -1931,6 +1931,93 @@ fn redefine_with_keep_art_selects_only_selectable_art_and_refuses_a_bad_switch()
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of symbol instances in the document.
|
||||
fn instance_count(s: &Session) -> usize {
|
||||
let mut n = 0;
|
||||
s.doc().unwrap().doc.walk(|c| n += usize::from(matches!(c.kind, NodeKind::SymbolInstance { .. })));
|
||||
n
|
||||
}
|
||||
|
||||
/// New Symbol with `keepArt: true` makes a symbol of the selection and makes it the current
|
||||
/// symbol, and the selected art stays ordinary art in its place, with its ids, still selected; the
|
||||
/// result has no instance id and nothing places the symbol. One undo step takes the symbol away
|
||||
/// and redo makes it again. Without `keepArt`, or with false, the art becomes an instance.
|
||||
#[test]
|
||||
fn new_symbol_with_keep_art_leaves_the_art_as_ordinary_art() {
|
||||
let mut s = session();
|
||||
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 steps = s.doc().unwrap().history.undo.len();
|
||||
select(&mut s, &[a, b]);
|
||||
let r = s.execute("symbol.new", &json!({"name": "Kept", "keepArt": true})).unwrap();
|
||||
assert_eq!((&r["name"], &r["id"]), (&json!("Kept"), &Value::Null), "{r}");
|
||||
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");
|
||||
assert_eq!(instance_count(&s), 0, "no instance");
|
||||
let list = s.execute("symbol.list", &json!({})).unwrap();
|
||||
assert_eq!((&list["current"], &list["symbols"][0]["name"], &list["symbols"][0]["instances"]), (&json!("Kept"), &json!("Kept"), &json!(0)));
|
||||
// The symbol's art is the pair: an instance placed from it is 120 × 50.
|
||||
let placed = NodeId(s.execute("symbol.place", &json!({"name": "Kept"})).unwrap()["id"].as_u64().unwrap());
|
||||
let w = bounds(&s, placed);
|
||||
assert!((w.width() - 120.0).abs() < 1e-6 && (w.height() - 50.0).abs() < 1e-6, "{w:?}");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "New Symbol is one undo step");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(s.doc().unwrap().doc.symbols.is_empty(), "undo takes the symbol away");
|
||||
assert_eq!((node(&s, a), node(&s, b)), (before.0.clone(), before.1.clone()), "and leaves the art");
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(s.execute("symbol.list", &json!({})).unwrap()["current"], json!("Kept"), "redo");
|
||||
assert_eq!(instance_count(&s), 0, "redo places no instance");
|
||||
// false, like no keepArt, makes the art an instance.
|
||||
for p in [json!({"name": "Plain", "ids": [a.0], "keepArt": false}), json!({"name": "Plain", "ids": [b.0]})] {
|
||||
let r = s.execute("symbol.new", &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());
|
||||
}
|
||||
|
||||
/// New 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 symbol instance in the art stays the
|
||||
/// instance it was. A `keepArt` that is not true or false is refused, with no symbol, no change and
|
||||
/// no undo step.
|
||||
#[test]
|
||||
fn new_symbol_with_keep_art_selects_only_selectable_art_and_refuses_a_bad_switch() {
|
||||
let mut s = session();
|
||||
let (inst, _, _) = 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.new", &json!({"name": "Bad", "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, &[]);
|
||||
let symbols = s.doc().unwrap().doc.symbols.len();
|
||||
let ids = [a.0, locked.0, hidden.0, inst.0];
|
||||
s.execute("symbol.new", &json!({"name": "Kept", "ids": ids, "keepArt": true})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.symbols.len(), symbols + 1);
|
||||
let selected = &s.doc().unwrap().selection.objects;
|
||||
assert!(selected.len() == 2 && selected.contains(&a) && selected.contains(&inst), "only the selectable art is selected: {selected:?}");
|
||||
for id in [a, locked, hidden] {
|
||||
assert!(matches!(node(&s, id).kind, NodeKind::Path { .. }), "{id:?} stays ordinary art");
|
||||
}
|
||||
assert!(matches!(node(&s, inst).kind, NodeKind::SymbolInstance { .. }), "the instance stays an instance");
|
||||
assert_eq!(instance_count(&s), 1, "no new instance");
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
//! `exportType` (`movieClip` | `graphic`), `type` (`dynamic` |
|
||||
//! `static`; a new symbol is dynamic), `registration` (0..8, the 9-point grid;
|
||||
//! 4 = centre), `alignToPixelGrid` (bool, off for a new symbol), `__edit` (true when editing an
|
||||
//! existing symbol). Help:
|
||||
//! existing symbol), `__keepArt` (true when a new symbol leaves the selection as ordinary art).
|
||||
//! Help:
|
||||
//! <https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-and-place-symbols.html>.
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
@@ -69,15 +70,23 @@ const EXPORT_TYPES: [(&str, &str); 2] = [("movieClip", "Movie Clip"), ("graphic"
|
||||
|
||||
pub(super) const SPEC: DialogSpec = DialogSpec { heading: |_| tl!("Symbol Options").into(), body, confirm, min_width: 320.0, ..DialogSpec::FORM };
|
||||
|
||||
/// Open Symbol Options to name a new symbol made from the selection.
|
||||
pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
/// Open Symbol Options to name a new symbol made from the selection. With `keep_art`, OK leaves
|
||||
/// the selection as ordinary art instead of replacing it with an instance.
|
||||
pub fn open(app: &mut VectorcraftApp, keep_art: bool) -> Result<Value, String> {
|
||||
let st = app.session.active().ok_or("no document open")?;
|
||||
if st.selection.is_empty() {
|
||||
return Err("nothing selected".into());
|
||||
}
|
||||
let name = st.doc.unique_symbol_name("New Symbol");
|
||||
let mut fields =
|
||||
json!({ "name": name, "exportType": "movieClip", "type": "dynamic", "registration": 4, "alignToPixelGrid": false, "__edit": false });
|
||||
let mut fields = json!({
|
||||
"name": name,
|
||||
"exportType": "movieClip",
|
||||
"type": "dynamic",
|
||||
"registration": 4,
|
||||
"alignToPixelGrid": false,
|
||||
"__edit": false,
|
||||
"__keepArt": keep_art,
|
||||
});
|
||||
if let Some(o) = fields.as_object_mut() {
|
||||
o.extend(slice_fields(None));
|
||||
}
|
||||
@@ -193,6 +202,9 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
|
||||
} else {
|
||||
let mut params = json!({ "name": name, "exportType": export, "type": kind, "registration": registration, "alignToPixelGrid": pixel });
|
||||
merge(&mut params, slice_params(d));
|
||||
if d.bool("__keepArt") {
|
||||
params["keepArt"] = json!(true);
|
||||
}
|
||||
app.run("symbol.new", params)
|
||||
};
|
||||
if r.is_ok() {
|
||||
|
||||
@@ -781,10 +781,17 @@ fn run_ui_part7(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
Ok(edit) => edit.unwrap_or(false),
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
let keep_art = match opt_bool(p, "keepArt") {
|
||||
Ok(keep) => keep.unwrap_or(false),
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
if edit || name.is_some() {
|
||||
if keep_art {
|
||||
return Some(Err("`keepArt` applies only to a new symbol".into()));
|
||||
}
|
||||
crate::dialogs::symbol_options::open_edit(app, name.as_deref())
|
||||
} else {
|
||||
crate::dialogs::symbol_options::open(app)
|
||||
crate::dialogs::symbol_options::open(app, keep_art)
|
||||
}
|
||||
}
|
||||
"ui.newBrush" => crate::dialogs::new_brush::open(app, p.get("ids").cloned()),
|
||||
|
||||
@@ -974,7 +974,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.symbolOptions",
|
||||
"Symbol Options…",
|
||||
"F8",
|
||||
"{name?} open Symbol Options (dialog `symbolOptions`, fields `name`, `exportType`: movieClip|graphic, `registration` 0..8). Without `name` and with a selection: New Symbol (default name the first free \"New Symbol\"/\"New Symbol N\", Export Type Movie Clip, Registration centre); OK runs symbol.new {name, exportType, registration}. With `edit: true` or `name`: edit that symbol; OK runs symbol.options {name, newName?, exportType, registration}",
|
||||
"{name?, edit?, keepArt?: false} open Symbol Options (dialog `symbolOptions`, fields `name`, `exportType`: movieClip|graphic, `registration` 0..8). Without `name` and with a selection: New Symbol (default name the first free \"New Symbol\"/\"New Symbol N\", Export Type Movie Clip, Registration centre); OK runs symbol.new {name, exportType, registration}, with keepArt: true when it was opened with keepArt: true (the selection stays ordinary art). With `edit: true` or `name`: edit that symbol; OK runs symbol.options {name, newName?, exportType, registration}; keepArt: true is then an error",
|
||||
),
|
||||
(
|
||||
"tool.options",
|
||||
|
||||
@@ -380,11 +380,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
ui.min_rect()
|
||||
});
|
||||
let zone = ui.interact(list_rect, ui.scope_id().with("symbols-drop"), Sense::hover());
|
||||
if !over_symbol
|
||||
&& let Some(ids) = widgets::art_drop(ui, &zone)
|
||||
&& let Err(e) = app.run("symbol.new", json!({ "ids": ids, "type": "dynamic" }))
|
||||
{
|
||||
app.status(e);
|
||||
if !over_symbol && let Some(ids) = widgets::art_drop(ui, &zone) {
|
||||
// Shift held at the release keeps the dropped art as ordinary art.
|
||||
let mut p = json!({ "ids": ids, "type": "dynamic" });
|
||||
if modifiers_at_release(ui).shift {
|
||||
p["keepArt"] = json!(true);
|
||||
}
|
||||
if let Err(e) = app.run("symbol.new", p) {
|
||||
app.status(e);
|
||||
}
|
||||
}
|
||||
// Redefine Symbol with the dropped art, which becomes an instance of it, in one undo step.
|
||||
if let Some((name, ids)) = redefine
|
||||
@@ -426,8 +430,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
} else if new.clicked() {
|
||||
// Alt skips Symbol Options: the symbol is made under the default name, dynamic as the
|
||||
// dialog's default.
|
||||
let (cmd, p) = if ui.input(|i| i.modifiers.alt) { ("symbol.new", json!({"type": "dynamic"})) } else { ("ui.symbolOptions", json!({})) };
|
||||
// dialog's default. Shift keeps the selected art as ordinary art, with or without Alt.
|
||||
let m = ui.input(|i| i.modifiers);
|
||||
let (cmd, mut p) = if m.alt { ("symbol.new", json!({"type": "dynamic"})) } else { ("ui.symbolOptions", json!({})) };
|
||||
if m.shift {
|
||||
p["keepArt"] = json!(true);
|
||||
}
|
||||
app.run(cmd, p).ok();
|
||||
}
|
||||
// Alt deletes an unused symbol without asking; a symbol with instances still asks.
|
||||
@@ -452,9 +460,11 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let inst = has_instances_selected(app);
|
||||
let name = json!({"name": sel});
|
||||
// Shift keeps the selected art as ordinary art instead of making it an instance.
|
||||
let redefine = if ui.input(|i| i.modifiers.shift) { json!({"name": sel, "keepArt": true}) } else { name.clone() };
|
||||
let shift = ui.input(|i| i.modifiers.shift);
|
||||
let redefine = if shift { json!({"name": sel, "keepArt": true}) } else { name.clone() };
|
||||
let new = if shift { json!({"keepArt": true}) } else { json!({}) };
|
||||
let items: [(&str, bool, &str, Value); 3] = [
|
||||
(tl!("New Symbol…"), has_sel, "ui.symbolOptions", json!({})),
|
||||
(tl!("New Symbol…"), has_sel, "ui.symbolOptions", new),
|
||||
(tl!("Redefine Symbol"), has_sel && sel.is_some(), "symbol.update", redefine),
|
||||
(tl!("Duplicate Symbol"), sel.is_some(), "symbol.duplicate", name.clone()),
|
||||
];
|
||||
@@ -573,14 +583,20 @@ fn art_redefine_drop(ui: &Ui, item: &egui::Response, doc: &Document, uid: Option
|
||||
/// Whether Alt (Option) is held for a drop: when the primary button went up in this frame, as it
|
||||
/// went up, else now.
|
||||
fn alt_at_release(ui: &Ui) -> bool {
|
||||
modifiers_at_release(ui).alt
|
||||
}
|
||||
|
||||
/// The modifiers held for a drop: when the primary button went up in this frame, as it went up,
|
||||
/// else now.
|
||||
fn modifiers_at_release(ui: &Ui) -> egui::Modifiers {
|
||||
ui.input(|i| {
|
||||
i.events
|
||||
.iter()
|
||||
.find_map(|e| match e {
|
||||
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, modifiers, .. } => Some(modifiers.alt),
|
||||
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, modifiers, .. } => Some(*modifiers),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(i.modifiers.alt)
|
||||
.unwrap_or(i.modifiers)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -928,6 +944,112 @@ mod tests {
|
||||
assert_eq!(art(&app, "Dot"), (1, 0), "without Shift the rectangle becomes an instance");
|
||||
}
|
||||
|
||||
/// `leaf_and_dot` with a selected 60 × 20 rectangle; returns its id.
|
||||
fn leaf_dot_and_rect() -> (VectorcraftApp, NodeId) {
|
||||
let mut app = leaf_and_dot();
|
||||
let rect = NodeId(app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 60, "height": 20})).unwrap()["id"].as_u64().unwrap());
|
||||
app.run("select.set", json!({"ids": [rect.0]})).unwrap();
|
||||
(app, rect)
|
||||
}
|
||||
|
||||
/// New Symbol… in the panel menu with Shift held opens Symbol Options, and its OK makes the
|
||||
/// symbol and leaves the selected art as ordinary art, still selected, in one undo step, though
|
||||
/// Shift is let go before OK; Cancel makes no symbol. Without Shift, OK makes the art an
|
||||
/// instance.
|
||||
#[test]
|
||||
fn shift_new_symbol_in_the_menu_keeps_the_art_as_ordinary_art() {
|
||||
let (mut app, rect) = leaf_dot_and_rect();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
click_menu_held(&ctx, &mut app, "New Symbol…", egui::Modifiers::SHIFT);
|
||||
assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_options::KIND));
|
||||
crate::dialogs::cancel(&mut app);
|
||||
assert_eq!(symbols(&mut app), ["Leaf", "Dot"], "Cancel makes no symbol");
|
||||
click_menu_held(&ctx, &mut app, "New Symbol…", egui::Modifiers::SHIFT);
|
||||
menu_frame(&ctx, &mut app, vec![egui::Event::ModifiersChanged(egui::Modifiers::NONE)]);
|
||||
let undo = undo_len(&app);
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(symbols(&mut app), ["Leaf", "Dot", "New Symbol"]);
|
||||
assert_eq!(art(&app, "New Symbol"), (0, 1), "the rectangle stays ordinary art");
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![rect], "and stays selected");
|
||||
assert_eq!(undo_len(&app), undo + 1, "one undo step");
|
||||
click_menu_held(&ctx, &mut app, "New Symbol…", egui::Modifiers::NONE);
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(art(&app, "New Symbol 2"), (1, 0), "without Shift the rectangle becomes an instance");
|
||||
}
|
||||
|
||||
/// Clicks the panel's New Symbol button with `modifiers` held.
|
||||
fn click_new(app: &mut VectorcraftApp, modifiers: egui::Modifiers) {
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
let out = frame_held(&ctx, app, vec![], modifiers);
|
||||
let at = clickable(&out).into_iter().find(|(l, _)| l == "New Symbol").expect("a New Symbol button").1;
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers };
|
||||
frame_held(&ctx, app, vec![egui::Event::PointerMoved(at), press(true), press(false)], modifiers);
|
||||
}
|
||||
|
||||
/// The New Symbol button with Shift held opens Symbol Options, whose OK keeps the selected art
|
||||
/// as ordinary art; with Shift and Alt it makes the symbol at once under the default name and
|
||||
/// keeps the art. Alt alone still makes the art an instance at once.
|
||||
#[test]
|
||||
fn shift_new_symbol_button_keeps_the_art_with_or_without_alt() {
|
||||
let (mut app, rect) = leaf_dot_and_rect();
|
||||
click_new(&mut app, egui::Modifiers::SHIFT);
|
||||
assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_options::KIND));
|
||||
assert_eq!(symbols(&mut app).len(), 2, "no symbol before OK");
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(art(&app, "New Symbol"), (0, 1), "Shift: the rectangle stays ordinary art");
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![rect]);
|
||||
let undo = undo_len(&app);
|
||||
click_new(&mut app, egui::Modifiers::SHIFT | egui::Modifiers::ALT);
|
||||
assert_eq!(dialog_kind(&app), None, "Alt skips Symbol Options");
|
||||
assert_eq!(symbols(&mut app), ["Leaf", "Dot", "New Symbol", "New Symbol 2"]);
|
||||
assert_eq!(art(&app, "New Symbol 2"), (0, 1), "Shift and Alt: the rectangle stays ordinary art");
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![rect]);
|
||||
assert_eq!(undo_len(&app), undo + 1, "one undo step");
|
||||
click_new(&mut app, egui::Modifiers::ALT);
|
||||
assert_eq!(art(&app, "New Symbol 3"), (1, 0), "Alt alone: the rectangle becomes an instance");
|
||||
}
|
||||
|
||||
/// Art dropped on the panel with Shift held as the primary button goes up becomes a new
|
||||
/// symbol and stays ordinary art, still selected, though Shift is let go later in the same
|
||||
/// frame; dropped without Shift, it becomes an instance.
|
||||
#[test]
|
||||
fn shift_art_drop_on_the_panel_keeps_the_art_as_ordinary_art() {
|
||||
let (mut app, rect) = leaf_dot_and_rect();
|
||||
let ctx = egui::Context::default();
|
||||
let at = pos2(180.0, 60.0);
|
||||
let release = |modifiers| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers };
|
||||
widgets::drag_art(&ctx, uid(&app).unwrap(), vec![rect]);
|
||||
frame_held(&ctx, &mut app, vec![egui::Event::PointerMoved(at)], egui::Modifiers::SHIFT);
|
||||
let undo = undo_len(&app);
|
||||
let let_go = egui::Event::ModifiersChanged(egui::Modifiers::NONE);
|
||||
frame_held(&ctx, &mut app, vec![release(egui::Modifiers::SHIFT), let_go], egui::Modifiers::SHIFT);
|
||||
assert_eq!(symbols(&mut app).len(), 3, "a new symbol");
|
||||
assert_eq!(art(&app, "New Symbol"), (0, 1), "the rectangle stays ordinary art");
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![rect], "and stays selected");
|
||||
assert_eq!(undo_len(&app), undo + 1, "one undo step");
|
||||
widgets::drag_art(&ctx, uid(&app).unwrap(), vec![rect]);
|
||||
frame_held(&ctx, &mut app, vec![egui::Event::PointerMoved(at)], egui::Modifiers::NONE);
|
||||
frame_held(&ctx, &mut app, vec![release(egui::Modifiers::NONE)], egui::Modifiers::NONE);
|
||||
assert_eq!(art(&app, "New Symbol 2"), (1, 0), "without Shift the rectangle becomes an instance");
|
||||
}
|
||||
|
||||
/// `ui.symbolOptions` takes `keepArt` only as true or false, and only for a new symbol.
|
||||
#[test]
|
||||
fn symbol_options_checks_keep_art() {
|
||||
let (mut app, _) = leaf_dot_and_rect();
|
||||
for bad in [json!("yes"), json!(1)] {
|
||||
let e = app.run("ui.symbolOptions", json!({ "keepArt": bad })).unwrap_err();
|
||||
assert!(e.contains("`keepArt` must be true or false"), "{bad}: {e}");
|
||||
}
|
||||
let e = app.run("ui.symbolOptions", json!({"edit": true, "name": "Dot", "keepArt": true})).unwrap_err();
|
||||
assert!(e.contains("only to a new symbol"), "{e}");
|
||||
assert_eq!(dialog_kind(&app), None);
|
||||
app.run("ui.symbolOptions", json!({"edit": true, "name": "Dot", "keepArt": false})).unwrap();
|
||||
assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_options::KIND));
|
||||
}
|
||||
|
||||
/// #4918: Select All Unused picks the symbols nothing places, Delete Symbol asks once and
|
||||
/// deletes them all in one undo step, and a click on a symbol picks one again.
|
||||
#[test]
|
||||
|
||||
+8
-2
@@ -3434,7 +3434,13 @@ already walks Image Trace. Short agent entry points:
|
||||
|
||||
- Symbols: `symbol.list` (each row includes `registration` 0..8, `exportType`: `movieClip`|`graphic`, `type`:
|
||||
`static`|`dynamic` and `alignToPixelGrid`),
|
||||
`symbol.new {name?, registration?, exportType?, nineSlice?, nineSliceGuides?, type?, alignToPixelGrid?, ids?}`,
|
||||
`symbol.new {name?, registration?, exportType?, nineSlice?, nineSliceGuides?, type?, alignToPixelGrid?, ids?, keepArt?: false}`
|
||||
(New Symbol: the selection, or `ids`, becomes the symbol's art and an instance of it in one undo step; with
|
||||
`keepArt: true` the art stays ordinary art in its place, with its ids, and stays selected unless it is hidden or
|
||||
locked, and the result's `id` is null; a `keepArt` other than true or false is an error; the Symbols panel sends
|
||||
`keepArt: true` when its New Symbol button, with or without Alt, or its New Symbol… menu item is used with Shift
|
||||
held, through Symbol Options' OK (`ui.symbolOptions {keepArt: true}`), and when art dragged off the canvas is
|
||||
released on the panel with Shift held),
|
||||
`symbol.options {name?, newName?, registration?, exportType?, nineSlice?, nineSliceGuides?, type?, alignToPixelGrid?}` (`nineSlice` bool turns
|
||||
9-slice guides on or off; `nineSliceGuides` is `[left, top, right, bottom]`, fractions of the symbol size in from
|
||||
each edge, each -16..16 with `left + right < 1` and `top + bottom < 1`, a quarter each when none are given; below 0
|
||||
@@ -9756,7 +9762,7 @@ thread. When `effect.expandAppearance` keeps a frame as type in a group (type wi
|
||||
effects are shadows, outer glows or Crop Marks), the type stays in the thread in the frame's place. Object › Expand
|
||||
(`object.expand`) outlines type with these two commands. `object.flattenTransparency` takes each frame of threaded text
|
||||
that it outlines (`textToOutlines`) or turns into flat regions or an image out of its thread in the same way.
|
||||
`symbol.new` (New Symbol) and `symbol.update` (Redefine Symbol, without `keepArt: true`) take each frame of threaded text in the selection out
|
||||
`symbol.new` (New Symbol) and `symbol.update` (Redefine Symbol), without `keepArt: true`, take each frame of threaded text in the selection out
|
||||
of its thread in the same way, and the symbol's art holds a copy of the frame with the text it shows. When every frame
|
||||
of a thread goes into the symbol, the copy of the last frame keeps the text it has no room for.
|
||||
|
||||
|
||||
@@ -1095,6 +1095,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Drag a symbol onto Delete Symbol to delete it** ([the tutorial](https://shop.smashingmagazine.com/2011/09/an-in-depth-study-of-symbols-in-illustrator-cs5/), [Symbols panel](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html)): a symbol dragged from the Symbols panel, in thumbnail view or a list view, and released on the Delete Symbol button is deleted as a click on the button deletes it (`symbol.delete`): an unused symbol asks "Delete the selected symbol?", a symbol with placed instances asks with Expand Instances, Delete Instances and Cancel, and Alt held at the release deletes an unused symbol without asking. VectorCraft's own rules: the dragged symbol is deleted, not the current one, in one undo step; a symbol that Select All Unused picked deletes every picked symbol still unused, after one question, and a symbol outside the pick is deleted on its own; the button is outlined while a symbol of the document is held over it; a library symbol, art, a name the document no longer has or a symbol dragged from another document is ignored. Tests: `panels::symbols::tests::symbol_dropped_on_delete_button_deletes_the_dragged_symbol_in_both_views`, `a_picked_symbol_dropped_on_delete_deletes_the_picked_symbols`, `delete_symbol_button_ignores_other_drops_and_releases_outside`.
|
||||
- **Alt-drag art onto a symbol to redefine it** ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=194), Modify a symbol instance section): art dragged off the canvas and released on a symbol in the Symbols panel with Alt (Option on macOS) held replaces that symbol's art, and every instance of the symbol updates, as Redefine Symbol does (`symbol.update` with the dragged art's `ids`). Released without Alt, the art still becomes a new symbol. VectorCraft's own rules: the symbol under the pointer is redefined, not the current one, in thumbnail view and both list views; the art becomes an instance of it, in one undo step; only that tile or row is outlined while the art is held over it with Alt; art of another document, objects the document no longer has and art that holds an instance of the symbol (directly, in an opacity mask or through the symbols it nests, which Redefine Symbol from the menu also refuses) change nothing. Tests: `panels::symbols::tests::alt_art_drop_on_a_symbol_redefines_that_symbol_in_one_step`, `alt_let_go_after_the_release_in_the_same_frame_still_redefines`, `a_plain_art_drop_on_a_symbol_makes_a_new_symbol`, `an_alt_art_drop_that_cannot_redefine_changes_nothing`, `a_secondary_button_release_drops_no_art`, `tests::brushsym::redefine_refuses_art_holding_an_instance_of_the_symbol`.
|
||||
- **Shift with Redefine Symbol keeps the art** ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/edit-symbols.html), Redefine a symbol with another object section): Redefine Symbol chosen from the Symbols panel menu with Shift held updates the symbol and every instance of it from the selected art, and the selected art stays ordinary art instead of becoming an instance (`symbol.update {keepArt: true}`). Chosen without Shift, the art still becomes an instance. VectorCraft's own rules: the art keeps its ids, layer and place in the stacking order and stays selected, apart from art that is hidden or locked; the result has no instance id; the redefine is one undo step and, for the symbol being edited, also leaves symbol editing mode; `keepArt` defaults to false, and a value other than true or false is an error. Tests: `panels::symbols::tests::shift_redefine_symbol_in_the_menu_keeps_the_art_as_ordinary_art`, `tests::brushsym::redefine_with_keep_art_leaves_the_art_as_ordinary_art`, `redefine_with_keep_art_selects_only_selectable_art_and_refuses_a_bad_switch`, `tests::symboledit::redefining_the_symbol_being_edited_with_keep_art_leaves_the_art_and_the_mode`.
|
||||
- **Shift with New Symbol keeps the art** ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=192), Create a symbol section): holding Shift while making a new symbol from the selected art, with the Symbols panel's New Symbol button, its New Symbol… menu item or by dragging the art onto the panel, adds the symbol and leaves the art as ordinary art instead of turning it into an instance (`symbol.new {keepArt: true}`). Without Shift, the art still becomes an instance. VectorCraft's own rules: Shift is read when the button or menu item is clicked, or when the dragged art is released, and Symbol Options' OK uses it even if Shift has been let go; Shift with Alt on the button makes the symbol without Symbol Options and keeps the art; the art keeps its ids, layer and place in the stacking order and stays selected, apart from art that cannot be selected (hidden or locked art, art in a hidden or locked group or layer, template art, art outside an isolated group, art on a locked artboard); frames of threaded text stay in their thread; the result has no instance id; the new symbol becomes the current symbol in one undo step; `keepArt` defaults to false, and a value other than true or false is an error. Tests: `panels::symbols::tests::shift_new_symbol_in_the_menu_keeps_the_art_as_ordinary_art`, `shift_new_symbol_button_keeps_the_art_with_or_without_alt`, `shift_art_drop_on_the_panel_keeps_the_art_as_ordinary_art`, `symbol_options_checks_keep_art`, `tests::brushsym::new_symbol_with_keep_art_leaves_the_art_as_ordinary_art`, `new_symbol_with_keep_art_selects_only_selectable_art_and_refuses_a_bad_switch`, `cmd::threads::tests::frames_kept_as_art_by_a_new_or_redefined_symbol_stay_in_their_thread`.
|
||||
- **Symbols › Select All Unused** ([Symbols panel](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html), #4918): the Symbols panel menu's Select All Unused shows the symbols nothing places selected (`symbol.unused`): instances in the art (opacity masks included), graph designs, pattern tiles and brush art count, and so do instances in a used symbol's art. Delete Symbol, the button or the menu item, then asks "Delete the selected symbols?" once and deletes those still unused in one undo step (`symbol.delete {names}`); Alt-click on the button deletes them without asking, and a click on a symbol picks just it again. Tests: `tests::brushsym::symbol_unused_lists_the_symbols_nothing_places_and_delete_takes_several`, `panels::symbols::tests::select_all_unused_picks_the_unused_symbols_and_delete_deletes_them`, `dialogs::symbol_delete::tests::several_symbols_get_the_plural_question`.
|
||||
- **Symbols › Sort by Name and the list views** ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html)): the Symbols panel menu's Sort by Name puts the symbols in alphabetical order (`symbol.sortByName`), and its Thumbnail View, Small List View and Large List View show them as thumbnails, in a compact list or in a list with larger thumbnails. VectorCraft's own rules: the sort ignores case and keeps names that differ only in case in their order; it changes the document's order, which `symbol.list` reports, as one undo step, keeps the current symbol and adds no undo step when the symbols are already in order; Thumbnail View is the default, Small List View has 18-point rows with 14-point thumbnails and Large List View 26-point rows with 22-point thumbnails, and a click or double-click on a symbol does the same in every view. `ui.panelView` sets the view of the Symbols panel, and of the Swatches and Graphic Styles panels, as their panel menus do. Tests: `tests::brushsym::symbol_sort_by_name_orders_the_symbols_in_one_undo_step`, `panels::symbols::tests::sort_by_name_and_the_small_and_large_list_views`, `panels::symbols::tests::panel_view_sets_the_view_of_each_panel`.
|
||||
- **The Symbols panel reads its current symbol from the document:** the Symbols panel and its panel menu read the current symbol on each frame without running `symbol.list`, which counts every symbol's instances by walking the whole document. The current symbol they show and act on is the one `symbol.list` reports, and an idle frame of the panel or its menu runs no command, so on macOS the native menu is not brought up to date on every frame while the panel is open. In a document with 200 symbols and 50,000 objects, the read takes 0.035 µs instead of 48.5 ms in a release build (thread CPU time on Linux, median of 7 runs); in a small document the difference is too small to notice. Tests: `tests::brushsym::current_symbol_is_the_current_symbol_list_answers`, `panels::symbols::tests::current_is_the_current_symbol_list_answers`, `panels::symbols::tests::idle_frames_of_the_panel_and_its_menu_run_no_command`; the timing probe is `panels::symbols::tests::current_symbol_read_timing`.
|
||||
|
||||
Reference in New Issue
Block a user