From be4d00c615944ef66c9d1d32e94a65789b60ad63 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 09:04:44 -0800 Subject: [PATCH 1/2] Symbols: a symbol dragged from another document places that document's symbol A symbol dragged from the Symbols panel carries the document it came from. Dropped on the canvas after another document became active, it no longer places a same-named symbol of the active document: symbol.placeFromDocument adds the dragged symbol, with the symbols and resources its art uses, and places it in one undo step. A symbol with the same name, art and Symbol Options is reused; one with the same name but other art or options is added under a free name. The pointer chip shows the dragged symbol, and a symbol whose document was closed places nothing. --- crates/engine/src/cmd/plugin_call.rs | 1 + crates/engine/src/cmd/symbollib.rs | 51 +++++++++- crates/engine/src/tests/symbollib.rs | 66 +++++++++++++ crates/ui-egui/src/canvas/context.rs | 9 +- crates/ui-egui/src/canvas/tests.rs | 103 +++++++++++++++++++- crates/ui-egui/src/panels/graphic_styles.rs | 2 +- crates/ui-egui/src/panels/swatches/dnd.rs | 3 +- crates/ui-egui/src/panels/symbols.rs | 11 ++- crates/ui-egui/src/widgets/drag.rs | 7 +- crates/ui-egui/src/widgets/look_tests.rs | 2 +- docs/mcp.md | 6 +- docs/target-app-parity.md | 1 + 12 files changed, 244 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/cmd/plugin_call.rs b/crates/engine/src/cmd/plugin_call.rs index 6c23161a9d..867c1f2ff0 100644 --- a/crates/engine/src/cmd/plugin_call.rs +++ b/crates/engine/src/cmd/plugin_call.rs @@ -64,6 +64,7 @@ const DENIED_PREFIXES: &[&str] = &[ "edit.newDocument", "edit.colorSettings", "edit.dropSelection", + "symbol.placeFromDocument", "artboard.copy", "artboard.cut", "text.rescanFonts", diff --git a/crates/engine/src/cmd/symbollib.rs b/crates/engine/src/cmd/symbollib.rs index b82be77f43..3e4774a370 100644 --- a/crates/engine/src/cmd/symbollib.rs +++ b/crates/engine/src/cmd/symbollib.rs @@ -20,7 +20,7 @@ use super::clipboard::Clipboard; use super::clipboard::resources::SwatchChoices; use super::swatch::str_list; use super::swatchlib::{FileData, LibraryFile, LibraryInfo, concealed_library_id, concealed_library_ids, shown_id, shown_library_id, stem}; -use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, has_doc, number_or, str_param}; +use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, has_doc, number_or, str_param, u64_req}; /// The extension of saved symbol libraries: native documents. pub const SYMBOLS_EXT: &str = vectorcraft_format::EXTENSION; @@ -54,6 +54,15 @@ pub fn specs() -> Vec { has_doc, add ), + cmd!( + "symbol.placeFromDocument", + "Place Symbol Instance", + [], + None, + "{sourceDocument: uid, name: a symbol of that document, x?, y?} place an instance of a symbol of another open document so its registration point is at (x, y) (default: the first artboard's center), as a symbol dragged from that document's Symbols panel onto the canvas is placed. The symbol, the symbols it nests and the resources they use are added as a drop of art from that document adds them, in the same undo step as the instance: a symbol the active document already has with the same name, art and Symbol Options is used, and one with the same name but other art or Symbol Options gets a number (\"Leaf 2\"); each symbol added takes its Symbol Options along. When sourceDocument is the active document, its own symbol is placed, as symbol.place places it. An error, with no edit, when that document is no longer open or has no symbol `name` → {id, name: the symbol's name in the active document}", + has_doc, + place_from_document + ), cmd!( "symbol.saveLibrary", "Save Symbol Library…", @@ -630,6 +639,46 @@ fn add(s: &mut Session, p: &Value) -> Result { Ok(out) } +/// `symbol.placeFromDocument`: an instance of symbol `name` of the open document `sourceDocument` +/// placed in the active document, with the symbol and the resources it uses added as a drop of +/// art from that document adds them, in one undo step. The source document is not changed. +fn place_from_document(s: &mut Session, p: &Value) -> Result { + const C: &str = "symbol.placeFromDocument"; + let uid = u64_req(p, "sourceDocument", C)?; + let name = str_param(p, "name").ok_or_else(|| bad(C, "missing `name`"))?; + let st = s.doc()?; + let centre = st.doc.artboards.first().map(|a| a.rect.center()).unwrap_or(Point::ZERO); + let at = Point::new(number_or(p, "x", centre.x, C)?, number_or(p, "y", centre.y, C)?); + let parent = st.target_parent()?; + let same = uid == st.uid; + let src = s.documents().iter().find(|d| d.uid == uid).map(|d| Arc::clone(&d.doc)); + let src = src.ok_or_else(|| bad(C, "the document the symbol came from is no longer open"))?; + if !src.symbols.iter().any(|sym| sym.name == name) { + return Err(bad(C, format!("no symbol named `{name}` in the document it came from"))); + } + // A symbol of the active document itself is placed as it is. + let clip = (!same).then(|| Clipboard::gather(&src, vec![instance(name)])); + // The source's colors are kept even where the active document has swatches of the same names. + let choices = SwatchChoices::parse(C, &json!({"swatchConflict": "add"}))?; + let (id, placed) = s.edit("Place Symbol Instance", |d, sel| { + let placed = match &clip { + // Each symbol added takes its Symbol Options along. + Some(clip) => { + let imported = clip.import_into(d, &choices, false)?; + let renamed = imported.renamed.iter().find(|r| r["kind"] == "symbol" && r["from"] == name).and_then(|r| r["to"].as_str()); + renamed.unwrap_or(name).to_string() + } + None => name.to_string(), + }; + let xf = place_xf(at, natural_size(d, &placed), d.symbol_registration(&placed)); + let id = d.alloc_id(); + d.insert(parent, usize::MAX, Node::new(id, NodeKind::SymbolInstance { symbol: placed.clone(), xf }))?; + sel.set([id]); + Ok((id, placed)) + })?; + Ok(json!({ "id": id.0, "name": placed })) +} + fn save(s: &mut Session, p: &Value) -> Result { const C: &str = "symbol.saveLibrary"; let st = s.doc()?; diff --git a/crates/engine/src/tests/symbollib.rs b/crates/engine/src/tests/symbollib.rs index c5d32e822a..02e45a7153 100644 --- a/crates/engine/src/tests/symbollib.rs +++ b/crates/engine/src/tests/symbollib.rs @@ -375,3 +375,69 @@ fn other_documents_symbols_load_and_unreadable_files_are_errors() { let bytes = vectorcraft_format::base64_decode(r["dataBase64"].as_str().unwrap()).unwrap(); assert_eq!(vectorcraft_format::load(&bytes).unwrap().symbols.len(), 1); } + +/// `symbol.placeFromDocument` places another open document's symbol in the active document as +/// one undo step, with the symbol it nests, the pattern its art uses and its Symbol Options. A +/// second placement uses what the first added; the source document is left as it was; a symbol +/// of the active document itself is placed as it is; a closed document, a name the document does +/// not have and bad params are errors that change nothing. +#[test] +fn another_documents_symbol_is_added_and_placed_in_one_step() { + let mut s = kit(); + let source = s.doc().unwrap().uid; + let source_doc = s.doc().unwrap().doc.clone(); + run(&mut s, "file.new", json!({"width": 100, "height": 100})); + let before = undo_len(&s); + let r = run(&mut s, "symbol.placeFromDocument", json!({"sourceDocument": source, "name": "Badge", "x": 30, "y": 40})); + assert_eq!(undo_len(&s), before + 1, "added and placed in one step"); + assert_eq!(r["name"], "Badge"); + let mut names = symbols(&s); + names.sort(); + assert_eq!(names, ["Badge", "Star"], "the nested Star came along"); + assert_eq!(doc(&s).symbol_registration("Badge"), SymbolRegistration(0)); + let placed = NodeId(r["id"].as_u64().unwrap()); + assert_eq!(s.doc().unwrap().selection.objects, [placed]); + let NodeKind::SymbolInstance { symbol, .. } = &doc(&s).node(placed).unwrap().kind else { panic!("not an instance") }; + assert_eq!(symbol, "Badge"); + let size = |d: &vectorcraft_doc::Document| d.unknown.get("symbolSizes").and_then(|m| m.get("Badge")).cloned(); + assert!(size(doc(&s)).is_some()); + assert_eq!(size(doc(&s)), size(&source_doc)); + // The Dots symbol brings its pattern and swatch. + run(&mut s, "symbol.placeFromDocument", json!({"sourceDocument": source, "name": "Dots"})); + assert!(doc(&s).pattern("Dots").is_some() && doc(&s).swatch("Dots").is_some()); + // Placed again, Badge is the one already added. + let count = doc(&s).symbols.len(); + let r = run(&mut s, "symbol.placeFromDocument", json!({"sourceDocument": source, "name": "Badge"})); + assert_eq!((r["name"].as_str(), doc(&s).symbols.len()), (Some("Badge"), count)); + run(&mut s, "edit.undo", json!({})); + run(&mut s, "edit.undo", json!({})); + run(&mut s, "edit.undo", json!({})); + assert!(symbols(&s).is_empty() && doc(&s).pattern("Dots").is_none()); + // The active document's own symbol, by its uid: placed, nothing added. + run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})); + run(&mut s, "symbol.new", json!({"name": "Star"})); + let own = s.doc().unwrap().uid; + let before = undo_len(&s); + let r = run(&mut s, "symbol.placeFromDocument", json!({"sourceDocument": own, "name": "Star", "x": 70, "y": 70})); + assert_eq!((undo_len(&s), r["name"].as_str(), symbols(&s)), (before + 1, Some("Star"), vec!["Star".to_string()])); + // Errors change nothing. + let before = (undo_len(&s), doc(&s).clone()); + for p in [ + json!({"sourceDocument": source, "name": "Nope"}), + json!({"sourceDocument": source}), + json!({"name": "Star"}), + json!({"sourceDocument": -1, "name": "Star"}), + json!({"sourceDocument": "1", "name": "Star"}), + json!({"sourceDocument": source, "name": "Star", "x": "10"}), + json!({"sourceDocument": u64::MAX, "name": "Star"}), + ] { + assert!(s.execute("symbol.placeFromDocument", &p).is_err(), "{p}"); + assert_eq!((undo_len(&s), doc(&s)), (before.0, &before.1), "{p}"); + } + // The source document is left as it was, and once it is closed its symbols are gone with it. + assert!(s.set_active(0)); + assert_eq!(*s.doc().unwrap().doc, *source_doc); + run(&mut s, "file.close", json!({"index": 0})); + let e = s.execute("symbol.placeFromDocument", &json!({"sourceDocument": source, "name": "Star"})).unwrap_err(); + assert!(e.to_string().contains("no longer open"), "{e}"); +} diff --git a/crates/ui-egui/src/canvas/context.rs b/crates/ui-egui/src/canvas/context.rs index cd98a214b7..8830416a28 100644 --- a/crates/ui-egui/src/canvas/context.rs +++ b/crates/ui-egui/src/canvas/context.rs @@ -73,10 +73,11 @@ pub(super) fn panel_drop(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respons } return; } - // A symbol from the Symbols panel: an instance centred where it is dropped, on art or not. - if let widgets::PanelDrag::Symbol(name) = &*d { + // A symbol from the Symbols panel: an instance centred where it is dropped, on art or not. A + // symbol of another document is added to this one first. + if let widgets::PanelDrag::Symbol { document, name } = &*d { let at = xf.to_doc(pos); - if let Err(e) = app.run("symbol.place", json!({"name": name, "x": at.x, "y": at.y})) { + if let Err(e) = app.run("symbol.placeFromDocument", json!({"sourceDocument": document, "name": name, "x": at.x, "y": at.y})) { app.status(e); } return; @@ -138,7 +139,7 @@ pub(super) fn panel_drop(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respons // Art dragged back onto the canvas: its move was already dropped. (A symbol was placed // above.) widgets::PanelDrag::Art(_) - | widgets::PanelDrag::Symbol(_) + | widgets::PanelDrag::Symbol { .. } | widgets::PanelDrag::LibrarySymbol { .. } | widgets::PanelDrag::LibraryGraphic { .. } => return, // A Libraries panel style or group only moves within that panel. diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 885ba3dcc6..112ef02d11 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -8812,7 +8812,8 @@ fn a_symbol_dropped_on_the_canvas_is_placed_there() { let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); // Released over empty canvas: an instance centred there. let at = xf.to_screen(Point::new(250.0, 180.0)); - egui::DragAndDrop::set_payload(&ctx, widgets::PanelDrag::Symbol(name.clone())); + let document = app.session.active().unwrap().uid; + egui::DragAndDrop::set_payload(&ctx, widgets::PanelDrag::Symbol { document, name: name.clone() }); let up = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }; frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at), up]); let st = app.session.active().unwrap(); @@ -8823,6 +8824,106 @@ fn a_symbol_dropped_on_the_canvas_is_placed_there() { assert!((c - xf.to_doc(at)).hypot() < 1e-6, "{c:?}"); } +/// A new active document with a symbol `name` made from a `w` by `h` rectangle and no art; → its +/// uid. +fn document_with_symbol(app: &mut VectorcraftApp, name: &str, w: f64, h: f64) -> u64 { + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": w, "height": h})).unwrap(); + app.session.execute("symbol.new", &json!({"name": name})).unwrap(); + app.session.execute("edit.clear", &json!({})).unwrap(); + app.session.active().unwrap().uid +} + +/// The natural size the active document records for symbol `name`. +fn symbol_size(app: &VectorcraftApp, name: &str) -> (f64, f64) { + let st = app.session.active().unwrap(); + let size = st.doc.unknown.get(vectorcraft_doc::SYMBOL_SIZES).and_then(|m| m.get(name)).cloned().unwrap(); + (size[0].as_f64().unwrap(), size[1].as_f64().unwrap()) +} + +/// A symbol dragged from one document's Symbols panel and released on the canvas after another +/// document with a different symbol of the same name became active places the dragged symbol: it +/// is added under a free name, the other document's symbol is left as it was, the source document +/// is not changed, and one Undo takes back both the symbol and the instance. +#[test] +fn a_symbol_dragged_from_another_document_places_that_documents_symbol() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let source = document_with_symbol(&mut app, "Leaf", 40.0, 20.0); + let ctx = egui::Context::default(); + // While Leaf is held, a document with a Leaf of its own becomes active. + egui::DragAndDrop::set_payload(&ctx, widgets::PanelDrag::Symbol { document: source, name: "Leaf".into() }); + document_with_symbol(&mut app, "Leaf", 10.0, 70.0); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let undo = app.session.active().unwrap().history.undo.len(); + let at = xf.to_screen(Point::new(250.0, 180.0)); + let up = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }; + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at), up]); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.symbols.iter().map(|s| s.name.as_str()).collect::>(), ["Leaf", "Leaf 2"]); + assert_eq!(st.history.undo.len(), undo + 1, "added and placed as one undo step"); + let placed = st.selection.objects.first().copied().expect("the placed instance is selected"); + let n = st.doc.node(placed).unwrap(); + assert!(matches!(&n.kind, NodeKind::SymbolInstance { symbol, .. } if symbol == "Leaf 2"), "{:?}", n.kind); + let b = n.geometric_bounds().unwrap(); + assert!((b.width() - 40.0).abs() < 1e-6 && (b.height() - 20.0).abs() < 1e-6, "the dragged symbol's size: {b:?}"); + assert!((b.center() - xf.to_doc(at)).hypot() < 1e-6, "{b:?}"); + assert_eq!(symbol_size(&app, "Leaf"), (10.0, 70.0), "this document's Leaf is unchanged"); + app.run("edit.undo", json!({})).unwrap(); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.symbols.iter().map(|s| s.name.as_str()).collect::>(), ["Leaf"]); + assert!(st.doc.node(placed).is_none()); + assert!(app.session.set_active(0)); + assert_eq!(app.session.active().unwrap().uid, source); + assert_eq!(app.session.active().unwrap().doc.symbols.len(), 1, "the source document is unchanged"); + assert_eq!(symbol_size(&app, "Leaf"), (40.0, 20.0)); +} + +/// A symbol dragged from a document that was closed before the release places nothing, even +/// where the active document has a symbol of the same name. +#[test] +fn a_symbol_whose_document_closed_places_nothing() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let source = document_with_symbol(&mut app, "Leaf", 40.0, 20.0); + document_with_symbol(&mut app, "Leaf", 10.0, 70.0); + app.session.execute("file.close", &json!({"index": 0})).unwrap(); + assert!(app.session.documents().iter().all(|d| d.uid != source)); + let ctx = egui::Context::default(); + egui::DragAndDrop::set_payload(&ctx, widgets::PanelDrag::Symbol { document: source, name: "Leaf".into() }); + frame(&mut app, &ctx, vec![]); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let undo = app.session.active().unwrap().history.undo.len(); + let at = xf.to_screen(Point::new(250.0, 180.0)); + let up = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }; + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at), up]); + let st = app.session.active().unwrap(); + assert_eq!(st.history.undo.len(), undo, "no edit"); + assert!(st.selection.objects.is_empty(), "nothing placed"); +} + +/// The chip at the pointer shows the dragged symbol from the document it was dragged from after +/// another document, without a symbol of that name, became active. +#[test] +fn the_pointer_chip_of_a_dragged_symbol_shows_its_own_documents_symbol() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + let source = document_with_symbol(&mut app, "Leaf", 40.0, 20.0); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + let ctx = egui::Context::default(); + egui::DragAndDrop::set_payload(&ctx, widgets::PanelDrag::Symbol { document: source, name: "Leaf".into() }); + let screen_rect = Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0))); + let run = |events| { + let mut out = + ctx.run_ui(egui::RawInput { screen_rect, events, ..Default::default() }, |ui| crate::panels::swatches::drag_preview(&app, ui.ctx())); + out.textures_delta.clear(); + out + }; + // The chip's area is drawn from its second frame. + run(vec![egui::Event::PointerMoved(pos2(200.0, 150.0))]); + let out = run(vec![]); + let thumbnail = out.shapes.iter().any(|c| matches!(&c.shape, Shape::Mesh(m) if m.texture_id != egui::TextureId::default())); + assert!(thumbnail, "the chip draws the source document's thumbnail of Leaf"); +} + #[test] fn a_library_symbol_dropped_on_the_canvas_is_added_and_placed_there_in_one_step() { let mut app = VectorcraftApp::new(Session::new(), Default::default()); diff --git a/crates/ui-egui/src/panels/graphic_styles.rs b/crates/ui-egui/src/panels/graphic_styles.rs index b99f9ec25b..cd7aa055b6 100644 --- a/crates/ui-egui/src/panels/graphic_styles.rs +++ b/crates/ui-egui/src/panels/graphic_styles.rs @@ -431,7 +431,7 @@ fn zone_input(ui: &Ui, zone: &Response, d: &Document, ev: &mut Events) { PanelDrag::Art(ids) => (None, ids.first().copied()), PanelDrag::Appearance(id) => (None, Some(*id)), PanelDrag::Paint { .. } - | PanelDrag::Symbol(_) + | PanelDrag::Symbol { .. } | PanelDrag::LibrarySymbol { .. } | PanelDrag::Brush { .. } | PanelDrag::LibraryBrush { .. } diff --git a/crates/ui-egui/src/panels/swatches/dnd.rs b/crates/ui-egui/src/panels/swatches/dnd.rs index 2adff72887..a7883f0031 100644 --- a/crates/ui-egui/src/panels/swatches/dnd.rs +++ b/crates/ui-egui/src/panels/swatches/dnd.rs @@ -302,7 +302,8 @@ pub(crate) fn drag_preview(app: &VectorcraftApp, ctx: &egui::Context) { None => return, }, PanelDrag::GraphicStyle(name) => return pointer_chip(ctx, |ui, r| crate::panels::graphic_styles::paint_style(app, ui, r, name)), - PanelDrag::Symbol(name) => match app.session.active() { + // Drawn from the document it was dragged from, whichever document is active now. + PanelDrag::Symbol { document, name } => match app.session.documents().iter().find(|st| st.uid == *document) { Some(st) => { return pointer_chip(ctx, |ui, r| crate::panels::symbols::chip(ui, &st.doc, &crate::panels::symbols::document_symbols(st), r, name)); } diff --git a/crates/ui-egui/src/panels/symbols.rs b/crates/ui-egui/src/panels/symbols.rs index a8392cdf50..c7a0c42639 100644 --- a/crates/ui-egui/src/panels/symbols.rs +++ b/crates/ui-egui/src/panels/symbols.rs @@ -296,7 +296,7 @@ pub(crate) fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui, reserve: f32) { pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); - let Some((doc, keys)) = app.session.active().map(|d| (d.doc.clone(), document_symbols(d))) else { return }; + let Some((doc, keys, document)) = app.session.active().map(|d| (d.doc.clone(), document_symbols(d), d.uid)) else { return }; let names: Vec = doc.symbols.iter().map(|s| s.name.clone()).collect(); let view = app.ui.symbols_view; let sel = current(app); @@ -316,7 +316,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { for n in &names { let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), h), Sense::click_and_drag()); // Dragged onto the canvas, the symbol is placed there. - widgets::drag_source(ui, &resp, || PanelDrag::Symbol(n.clone())); + widgets::drag_source(ui, &resp, || PanelDrag::Symbol { document, name: n.clone() }); if on(n) { ui.painter().rect_filled(r, 0.0, t.row_selected); } else if resp.hovered() { @@ -342,7 +342,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { ui.horizontal_wrapped(|ui| { for n in &names { let (r, resp) = ui.allocate_exact_size(vec2(44.0, 44.0), Sense::click_and_drag()); - widgets::drag_source(ui, &resp, || PanelDrag::Symbol(n.clone())); + widgets::drag_source(ui, &resp, || PanelDrag::Symbol { document, name: n.clone() }); chip(ui, &doc, &keys, r.shrink(2.0), n); let on = on(n); ui.painter().rect_stroke( @@ -771,13 +771,14 @@ mod tests { let doc = &app.session.active().unwrap().doc; let first = doc.layers[0].children().unwrap().first().unwrap(); assert!(matches!(first.kind, NodeKind::SymbolInstance { .. }), "the art became an instance"); - // Dragging the symbol's tile out of the panel carries the symbol. + // Dragging the symbol's tile out of the panel carries the symbol and its document. frame(&ctx, &mut app, vec![]); let tile = pos2(26.0, 26.0); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile), button(tile, true)]); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(40.0, 40.0))]); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(80.0, 80.0))]); - assert_eq!(egui::DragAndDrop::payload::(&ctx).as_deref(), Some(&PanelDrag::Symbol(names[0].clone()))); + let document = app.session.active().unwrap().uid; + assert_eq!(egui::DragAndDrop::payload::(&ctx).as_deref(), Some(&PanelDrag::Symbol { document, name: names[0].clone() })); } /// One headless frame of the panel menu; returns its painted labels. diff --git a/crates/ui-egui/src/widgets/drag.rs b/crates/ui-egui/src/widgets/drag.rs index 1a9c280f81..ed28c31e30 100644 --- a/crates/ui-egui/src/widgets/drag.rs +++ b/crates/ui-egui/src/widgets/drag.rs @@ -23,9 +23,10 @@ pub enum PanelDrag { /// (`symbol.new`), the Swatches panel a pattern swatch of a copy (`object.pattern.make`) and the /// Brushes panel an Art brush (`brush.new`). Art(Vec), - /// A Symbols panel symbol: the canvas places an instance of it centred where it is dropped - /// (`symbol.place`). - Symbol(String), + /// A Symbols panel symbol (`document`: the uid of the document whose panel it was dragged + /// from): the canvas places an instance of it centered where it is dropped, adding the symbol + /// first when another document is active by then (`symbol.placeFromDocument`). + Symbol { document: u64, name: String }, /// A symbol of a symbol library panel (`name`: its name in `library`): the canvas adds it to the /// document's Symbols and places an instance where it is dropped (`symbol.addFromLibrary` with /// `place`). diff --git a/crates/ui-egui/src/widgets/look_tests.rs b/crates/ui-egui/src/widgets/look_tests.rs index 274861386b..c6c241e504 100644 --- a/crates/ui-egui/src/widgets/look_tests.rs +++ b/crates/ui-egui/src/widgets/look_tests.rs @@ -421,7 +421,7 @@ fn a_popover_stays_open_for_a_click_on_its_anchor_or_during_a_panel_drag() { shown.get() }; let far = Some(pos2(500.0, 350.0)); - let panel_drag = || Some(PanelDrag::Symbol("s".into())); + let panel_drag = || Some(PanelDrag::Symbol { document: 1, name: "s".into() }); // Whether it is open after: a click elsewhere; a click on its anchor that doesn't toggle it; // a panel drag released elsewhere. let open = [open_after_click(far, None), open_after_click(None, None), open_after_click(far, panel_drag())]; diff --git a/docs/mcp.md b/docs/mcp.md index 7c45340f2b..cbe369556f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3414,7 +3414,11 @@ already walks Image Trace. Short agent entry points: art, where it is, snaps the art again after it is edited, and does not count instances in `select.object.notAlignedToPixelGrid`; `alignToPixelGrid` alone with the value the symbol already has adds no undo step), - `symbol.place {name?, x?, y?}`, `symbol.breakLink {ids?}` (the art keeps the instance's opacity mask and its bounding box, square after + `symbol.place {name?, x?, y?}`, `symbol.placeFromDocument {sourceDocument, name, x?, y?}` (an instance of a symbol + of another open document, as a symbol dragged from that document's Symbols panel onto the canvas places it: the + symbol, the symbols it nests and the resources they use are added as `edit.dropSelection` adds them, in the same + undo step, and a symbol with the same name but other art or Symbol Options is added under a free name; an error + when that document is no longer open; plug-ins cannot call it), `symbol.breakLink {ids?}` (the art keeps the instance's opacity mask and its bounding box, square after `object.resetBoundingBox`; a hidden or locked instance's art stays hidden or locked and is not selected), `symbol.replace`, `symbol.edit {id?, ids?, name?, x?, y?, artboard?, viewCenter?}` (symbol editing mode: the symbol's art on a temporary diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ea070aeba0..daa5de4e5a 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1281,6 +1281,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur As VectorCraft's own rule, a zoom marquee that Cmd+Space starts while the Type tool edits text keeps the marquee's Space rules after Cmd is let go: Space held since the press sizes it, Space pressed again moves it ([the help page](https://helpx.adobe.com/illustrator/using/viewing-artwork.html) describes holding the spacebar to move the marquee), and that Space types no space, nor does it during an animated zoom drag. With no zoom drag, Space types a space. Test: `canvas::tests::space_moves_a_text_edit_zoom_marquee_after_cmd_is_let_go`. - **Swatches panel clicks:** Ctrl/Cmd-clicking New Swatch makes a spot color, and Ctrl/Cmd+Shift-clicking it makes a global process color. - **Panel drag and drop:** art dragged off the canvas onto the Symbols panel becomes a symbol, art dragged onto the Swatches panel becomes a pattern swatch, and art dropped on the Brushes panel opens New Brush for that art; a symbol dragged onto the canvas places an instance where it is dropped, and a brush dragged onto a path is applied to it. + A symbol dragged from one document's Symbols panel and dropped on the canvas after another document became active places the dragged symbol, not a symbol of the same name in the active document (`symbol.placeFromDocument`). VectorCraft's own rules: the symbol, the symbols it nests and the resources they use are added to the active document as a drop of art from the other document adds them, in the same undo step as the instance; a symbol the document already has with the same art and Symbol Options is used, and one with the same name but other art or options is added under a free name ("Leaf 2"); the chip at the pointer shows the dragged symbol; a symbol whose document was closed before the drop places nothing and the status bar shows the error. Tests: `canvas::tests::a_symbol_dragged_from_another_document_places_that_documents_symbol`, `a_symbol_whose_document_closed_places_nothing`, `the_pointer_chip_of_a_dragged_symbol_shows_its_own_documents_symbol`, `tests::symbollib::another_documents_symbol_is_added_and_placed_in_one_step`. New Brush asks for the type of brush first, as the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page (archived copy) describes. The Brushes panel's New Brush button, its menu's New Brush… and art dropped on the panel open the New Brush dialog, where Scatter Brush, Art Brush and Pattern Brush need selected or dropped art. OK opens that type's Brush Options for the new brush, and their OK makes the brush with the name and options set; Cancel in either dialog adds no brush (`ui.newBrush`). The menu's New Calligraphic Brush, New Bristle Brush and New Art, Scatter and Pattern Brush from Selection items still make a brush at once. - **Panel drag and drop:** art dragged off the canvas onto the Symbols panel becomes a symbol, onto the Swatches panel a pattern swatch and onto the Brushes panel an Art brush; a symbol dragged onto the canvas places an instance where it is dropped, and a brush dragged onto a path is applied to it. In the Brushes panel, a brush dragged onto another brush of its type goes before or after it, by the half of the tile or row the pointer is over, and a bar marks the slot while the brush is held there (`brush.move`); the move is one undo step. Brushes move only within their type, as the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page states: a brush dropped on a brush of another type stays where it is, and the status bar shows "brushes move only within their type". From 55590e1131f937defc162580ab99deb35e12688e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 09:02:39 -0800 Subject: [PATCH 2/2] Symbols: Delete Symbol tests carry the dragged symbol's document The Delete Symbol drop tests that landed on main set the dragged symbol's document through the removed panel state key and built the old tuple payload. They now build PanelDrag::Symbol with the active document's uid, as the New Symbol tests do. --- crates/ui-egui/src/panels/symbols.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/symbols.rs b/crates/ui-egui/src/panels/symbols.rs index a0741810d4..b98ec88c9a 100644 --- a/crates/ui-egui/src/panels/symbols.rs +++ b/crates/ui-egui/src/panels/symbols.rs @@ -2217,14 +2217,14 @@ mod tests { let ctx = egui::Context::default(); crate::theme::install_fonts(&ctx); // The payloads are set directly, as if dragged from this document's panel. - set_pstate(&ctx, DRAG_DOC, uid(&app)); + let document = uid(&app).expect("an active document"); let trash = button_rect(&ctx, &mut app, "Delete Symbol"); let elsewhere = trash.center() - vec2(0.0, 60.0); let cases = [ ("a library symbol", PanelDrag::LibrarySymbol { library: "basic-shapes".into(), name: "Leaf".into() }, trash.center()), ("art", PanelDrag::Art(vec![leaf]), trash.center()), - ("a stale name", PanelDrag::Symbol("Gone".into()), trash.center()), - ("a symbol released elsewhere", PanelDrag::Symbol("Dot".into()), elsewhere), + ("a stale name", PanelDrag::Symbol { document, name: "Gone".into() }, trash.center()), + ("a symbol released elsewhere", PanelDrag::Symbol { document, name: "Dot".into() }, elsewhere), ]; for (case, drag, at) in cases { egui::DragAndDrop::set_payload(&ctx, drag); @@ -2241,7 +2241,7 @@ mod tests { frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile), button(tile, true)]); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(40.0, 40.0))]); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(80.0, 80.0))]); - assert_eq!(egui::DragAndDrop::payload::(&ctx).as_deref(), Some(&PanelDrag::Symbol("Leaf".into()))); + assert_eq!(egui::DragAndDrop::payload::(&ctx).as_deref(), Some(&PanelDrag::Symbol { document, name: "Leaf".into() })); app.run("symbol.delete", json!({"name": "Leaf"})).unwrap(); let undo = app.session.active().unwrap().history.undo.len(); let out = frame_held(&ctx, &mut app, vec![egui::Event::PointerMoved(trash.center())], egui::Modifiers::NONE); @@ -2253,7 +2253,7 @@ mod tests { frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile), button(tile, true)]); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(40.0, 40.0))]); frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(80.0, 80.0))]); - assert_eq!(egui::DragAndDrop::payload::(&ctx).as_deref(), Some(&PanelDrag::Symbol("Dot".into()))); + assert_eq!(egui::DragAndDrop::payload::(&ctx).as_deref(), Some(&PanelDrag::Symbol { document, name: "Dot".into() })); app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 30})).unwrap(); app.run("symbol.new", json!({"name": "Dot"})).unwrap();