diff --git a/crates/ui-egui/src/panels/symbols.rs b/crates/ui-egui/src/panels/symbols.rs index d0f024cb2d..aa6254dbbb 100644 --- a/crates/ui-egui/src/panels/symbols.rs +++ b/crates/ui-egui/src/panels/symbols.rs @@ -414,7 +414,13 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { app.run(cmd, p).ok(); } // Alt deletes an unused symbol without asking; a symbol with instances still asks. - if widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Symbol"), false, sel.is_some() || !marked.is_empty(), 24.0).clicked() { + let trash = widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Symbol"), false, sel.is_some() || !marked.is_empty(), 24.0); + // A symbol dragged from the panel and dropped on Delete Symbol is deleted as a click deletes + // it: the dragged symbol, or every symbol Select All Unused picked when it is one of them. + if let Some(name) = symbol_dropped(ui, &trash, &names, uid) { + let picked = if marked.contains(&name) { &marked[..] } else { &[] }; + delete(app, picked, Some(&name), super::alt_held(ui)); + } else if trash.clicked() { delete(app, &marked, sel.as_deref(), super::alt_held(ui)); } }); @@ -506,8 +512,8 @@ fn drag_symbol(ui: &Ui, resp: &egui::Response, name: &str, uid: Option) { } /// The symbol of the active document (`uid`, whose symbols are `names`) dragged from the panel and -/// released on `button` this frame, if any; `button` is outlined while one is held over it. A -/// symbol dragged from another document is ignored. +/// released on `button` this frame, if any; `button` is outlined while one is held over it, also +/// when it is disabled for clicks. A symbol dragged from another document is ignored. fn symbol_dropped(ui: &Ui, button: &egui::Response, names: &[String], uid: Option) -> Option { let held = button.dnd_hover_payload::()?; let PanelDrag::Symbol(name) = &*held else { return None }; @@ -2049,6 +2055,185 @@ mod tests { assert_eq!(symbols(&mut app), ["Leaf", "Dot"], "no copy in the first document"); } + /// Drags the symbol at `from` in the panel onto `to` and releases it there with `modifiers` + /// held; returns the frame in which it is held over `to`. + fn drag_onto(ctx: &egui::Context, app: &mut VectorcraftApp, from: Pos2, to: Pos2, modifiers: egui::Modifiers) -> egui::FullOutput { + // egui finds what the press hits among the widgets of the frame before, so the panel is + // drawn once first (the frame before may have drawn the panel menu). + frame(ctx, app, vec![]); + frame(ctx, app, vec![egui::Event::PointerMoved(from), button(from, true)]); + frame(ctx, app, vec![egui::Event::PointerMoved(from + vec2(40.0, 40.0))]); + frame(ctx, app, vec![egui::Event::PointerMoved(from + vec2(80.0, 80.0))]); + let held = frame_held(ctx, app, vec![egui::Event::PointerMoved(to)], egui::Modifiers::NONE); + frame_held(ctx, app, vec![button(to, false)], modifiers); + held + } + + /// A symbol dragged from the panel, in Thumbnail View or a list view, and dropped on Delete + /// Symbol is deleted as a click on the button deletes it, though another symbol is current. The + /// button is outlined while the symbol is held over it. A symbol with instances asks the in-use + /// question, with Alt held too, and Cancel changes nothing; an unused one asks "Delete the + /// selected symbol?", or with Alt held is deleted at once; each deletion is one undo step. + #[test] + fn symbol_dropped_on_delete_button_deletes_the_dragged_symbol_in_both_views() { + for view in ["thumbnail", "smallList"] { + let mut app = leaf_and_dot(); + app.run("ui.panelView", json!({"panel": "symbols", "view": view})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let trash = button_rect(&ctx, &mut app, "Delete Symbol"); + let first = |ctx: &egui::Context, app: &mut VectorcraftApp, name: &str| { + if view == "thumbnail" { pos2(26.0, 26.0) } else { panel_labels(ctx, app, &[name])[0].1 } + }; + let before = app.session.active().unwrap().doc.clone(); + let undo = app.session.active().unwrap().history.undo.len(); + // Leaf, which an instance uses, while Dot is current. + let leaf = first(&ctx, &mut app, "Leaf"); + for alt in [egui::Modifiers::NONE, egui::Modifiers::ALT] { + let held = drag_onto(&ctx, &mut app, leaf, trash.center(), alt); + assert!(outlined(&held, trash), "{view}: outlined while Leaf is held over it"); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_delete::USED), "{view} {alt:?}"); + assert_eq!(app.ui.dialog.as_ref().unwrap().fields["name"], json!("Leaf"), "{view}: the dragged symbol"); + crate::dialogs::cancel(&mut app); + assert!(Arc::ptr_eq(&before, &app.session.active().unwrap().doc), "{view} {alt:?}: Cancel changes nothing"); + } + assert_eq!(current(&app).as_deref(), Some("Dot"), "{view}"); + drag_onto(&ctx, &mut app, leaf, trash.center(), egui::Modifiers::NONE); + app.ui.dialog.as_mut().unwrap().fields.insert("discard".into(), json!(true)); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!((symbols(&mut app), art(&app, "Leaf").0), (vec!["Dot".to_string()], 0), "{view}: Delete Instances"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1, "{view}: one undo step"); + // Dot, which nothing uses, now comes first: Yes deletes it, and so does a drop with Alt. + let dot = first(&ctx, &mut app, "Dot"); + drag_onto(&ctx, &mut app, dot, trash.center(), egui::Modifiers::NONE); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_delete::KIND), "{view}"); + assert_eq!(app.ui.dialog.as_ref().unwrap().fields["name"], json!("Dot"), "{view}"); + crate::dialogs::confirm(&mut app).unwrap(); + assert!(symbols(&mut app).is_empty(), "{view}: Yes deletes Dot"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 2, "{view}: one undo step"); + app.run("edit.undo", json!({})).unwrap(); + drag_onto(&ctx, &mut app, dot, trash.center(), egui::Modifiers::ALT); + assert_eq!(dialog_kind(&app), None, "{view}: Alt asks nothing for an unused symbol"); + assert!(symbols(&mut app).is_empty(), "{view}: Alt deletes Dot"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 2, "{view}: one undo step"); + app.run("edit.undo", json!({})).unwrap(); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!((symbols(&mut app), art(&app, "Leaf").0), (vec!["Leaf".to_string(), "Dot".to_string()], 1), "{view}"); + } + } + + /// A symbol Select All Unused picked, dropped on Delete Symbol, deletes every picked symbol + /// still unused, after one question or with Alt held at once, in one undo step; a symbol the + /// pick left out is asked about and deleted on its own. + #[test] + fn a_picked_symbol_dropped_on_delete_deletes_the_picked_symbols() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + for (i, name) in ["A", "B", "C"].into_iter().enumerate() { + app.run("shape.rectangle", json!({"x": 10.0 + 40.0 * i as f64, "y": 10, "width": 30, "height": 20})).unwrap(); + let id = app.run("symbol.new", json!({"name": name})).unwrap()["id"].as_u64().unwrap(); + // A and C lose their instances; B keeps its own. + if name != "B" { + app.run("edit.clear", json!({"ids": [id]})).unwrap(); + } + } + app.run("ui.panelView", json!({"panel": "symbols", "view": "smallList"})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let trash = button_rect(&ctx, &mut app, "Delete Symbol"); + let rows: HashMap = panel_labels(&ctx, &mut app, &["A", "B", "C"]).into_iter().collect(); + let undo = app.session.active().unwrap().history.undo.len(); + click_menu(&ctx, &mut app, "Select All Unused"); + let held = drag_onto(&ctx, &mut app, rows["A"], trash.center(), egui::Modifiers::NONE); + assert!(outlined(&held, trash)); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_delete::KIND)); + assert_eq!(app.ui.dialog.as_ref().unwrap().fields["names"], json!(["A", "C"]), "asked once, about both"); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!(symbols(&mut app), ["B"]); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1, "one undo step"); + app.run("edit.undo", json!({})).unwrap(); + // With Alt held, the picked symbols go without a question. + click_menu(&ctx, &mut app, "Select All Unused"); + drag_onto(&ctx, &mut app, rows["C"], trash.center(), egui::Modifiers::ALT); + assert_eq!(dialog_kind(&app), None); + assert_eq!(symbols(&mut app), ["B"]); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1, "one undo step"); + app.run("edit.undo", json!({})).unwrap(); + // B, which the pick left out, is asked about on its own. + click_menu(&ctx, &mut app, "Select All Unused"); + drag_onto(&ctx, &mut app, rows["B"], trash.center(), egui::Modifiers::ALT); + assert_eq!(dialog_kind(&app), Some(crate::dialogs::symbol_delete::USED)); + let fields = &app.ui.dialog.as_ref().unwrap().fields; + assert_eq!((fields.get("name"), fields.get("names")), (Some(&json!("B")), None)); + crate::dialogs::confirm(&mut app).unwrap(); + assert_eq!(symbols(&mut app), ["A", "C"]); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1, "one undo step"); + } + + /// Delete Symbol takes only a symbol of the active document's that it still has: a library + /// symbol, art, a name the document does not have, a symbol released elsewhere, a symbol deleted + /// while it is dragged and a symbol dragged from another document with a symbol of the same name + /// delete nothing, ask nothing and add no undo step, and the button is not outlined for them. + #[test] + fn delete_symbol_button_ignores_other_drops_and_releases_outside() { + let mut app = leaf_and_dot(); + let leaf = instance_of(&app, "Leaf").expect("a Leaf instance"); + let undo = app.session.active().unwrap().history.undo.len(); + 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 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), + ]; + for (case, drag, at) in cases { + egui::DragAndDrop::set_payload(&ctx, drag); + let out = frame_held(&ctx, &mut app, vec![egui::Event::PointerMoved(at)], egui::Modifiers::NONE); + assert!(!outlined(&out, trash), "{case}: not outlined"); + frame_held(&ctx, &mut app, vec![button(at, false)], egui::Modifiers::ALT); + assert_eq!(symbols(&mut app), ["Leaf", "Dot"], "{case}"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo, "{case}: no undo step"); + assert_eq!(dialog_kind(&app), None, "{case}"); + egui::DragAndDrop::clear_payload(&ctx); + } + // Leaf is deleted by command while it is dragged, then released on the button. + 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("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); + assert!(!outlined(&out, trash), "a deleted symbol: not outlined"); + frame_held(&ctx, &mut app, vec![button(trash.center(), false)], egui::Modifiers::ALT); + assert_eq!((symbols(&mut app), dialog_kind(&app)), (vec!["Dot".to_string()], None), "a deleted symbol"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo, "a deleted symbol: no undo step"); + // Dot is dragged, and a new document with a Dot of its own becomes active before the release. + 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()))); + 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(); + app.run("edit.clear", json!({})).unwrap(); + let other = app.session.active().unwrap().history.undo.len(); + let trash = button_rect(&ctx, &mut app, "Delete Symbol"); + let out = frame_held(&ctx, &mut app, vec![egui::Event::PointerMoved(trash.center())], egui::Modifiers::NONE); + assert!(!outlined(&out, trash), "another document: not outlined"); + frame_held(&ctx, &mut app, vec![button(trash.center(), false)], egui::Modifiers::ALT); + assert_eq!((symbols(&mut app), dialog_kind(&app)), (vec!["Dot".to_string()], None), "the active document keeps its Dot"); + assert_eq!(app.session.active().unwrap().history.undo.len(), other, "another document: no undo step"); + assert!(app.session.set_active(0)); + assert_eq!(symbols(&mut app), ["Dot"], "the first document keeps its Dot"); + } + /// CPU time of this thread in nanoseconds where the system reports it (Linux), else `None`. fn thread_cpu_ns() -> Option { std::fs::read_to_string("/proc/thread-self/schedstat").ok()?.split_whitespace().next()?.parse().ok() diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index a6aa8615b3..68bd8fda42 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1056,6 +1056,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Delete Symbol asks first** ([Symbols panel](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html), [symbol libraries](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/create-or-import-symbol-libraries.html), [Alt-click Delete](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)): the Symbols panel's Delete Symbol button and menu item ask "Delete the selected symbol?" with Yes and No for a symbol no instance uses. For a symbol with placed instances they ask with Expand Instances (the instances become ordinary art), Delete Instances and Cancel; either Instances button deletes the symbol in one undo step. Alt-click on the button deletes an unused symbol without asking and still asks about one with instances. A question left open while another document became active deletes nothing. `symbol.delete` itself does not ask. Tests: `panels::symbols::tests::delete_symbol_asks_first_and_alt_click_deletes_an_unused_symbol_at_once`, `the_in_use_question_expands_or_deletes_the_instances`, `a_stale_delete_symbol_question_deletes_nothing`, `the_delete_symbol_questions_show_their_buttons`. - **Symbols panel context menu** ([Symbols panel](https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/symbols-panel-options.html)): right-clicking a symbol in thumbnail view or list view displays a context menu with Place Symbol Instance (passes view center or artboard center), Edit Symbol, Duplicate Symbol, Delete Symbol, Break Link to Symbol (enabled when canvas selection includes instances of this symbol), and Select All Instances. Right-clicking an unselected symbol selects it first (`symbol.setCurrent`). Tests: `panels::symbols::tests::right_click_context_menu_in_symbols_panel_runs_actions`. - **Drag a symbol onto New Symbol to duplicate it** ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=197), Duplicate a symbol in the panel section): a symbol dragged from the Symbols panel, in thumbnail view or a list view, and released on the New Symbol button is copied as Duplicate Symbol copies it (`symbol.duplicate`), with no Symbol Options dialog, even while no art is selected and the button is disabled for clicks. VectorCraft's own rules: the copy is made of the dragged symbol, not the current one, under Duplicate Symbol's default name, in one undo step; the current symbol and the selection stay as they were and no instance is placed; 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_new_button_duplicates_the_dragged_symbol_in_both_views`, `new_symbol_button_ignores_other_drops_and_releases_outside`, `a_symbol_dragged_from_another_document_is_not_duplicated`. + - **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`. - **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`.