From 7508f7cfe326d231fd4ab89687a4153f7cac5e34 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 07:44:03 -0800 Subject: [PATCH] Graphic Styles: a style dropped on New Graphic Style is duplicated at the end of the list A graphic style dragged from the panel onto the New Graphic Style button runs Duplicate Graphic Style. The button takes the drop with no art selected and is outlined while a style is held over it. A dragged style that is highlighted brings the other highlighted styles, copied in panel order in one undo step, and the copies are highlighted. graphicStyle.duplicate now adds the copy at the end of the list instead of right after its source, for the panel menu's command and the drop. The list's drop zone no longer reaches over the footer when the list is shorter than 220 pt, so a style released on New Graphic Style or Delete is not moved to the end of the list. --- crates/engine/src/cmd/style.rs | 12 +- crates/engine/src/tests/styles.rs | 26 ++++ crates/ui-egui/src/panels/graphic_styles.rs | 160 +++++++++++++++++++- docs/mcp.md | 4 +- docs/target-app-parity.md | 1 + 5 files changed, 195 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/style.rs b/crates/engine/src/cmd/style.rs index 5780e65ed8..33c9ec67bb 100644 --- a/crates/engine/src/cmd/style.rs +++ b/crates/engine/src/cmd/style.rs @@ -53,7 +53,15 @@ pub fn specs() -> Vec { has_doc, style_delete ), - cmd!("graphicStyle.duplicate", "Duplicate Graphic Style", ["Window", "Graphic Styles"], None, "{name} → {name}", has_doc, style_duplicate), + cmd!( + "graphicStyle.duplicate", + "Duplicate Graphic Style", + ["Window", "Graphic Styles"], + None, + "{name} a copy of the style at the end of the list, named ` copy` (` copy 2`… when that is taken); no object is linked to it → {name}", + has_doc, + style_duplicate + ), cmd!( query "graphicStyle.list", "List Graphic Styles", @@ -431,7 +439,7 @@ fn style_duplicate(s: &mut Session, p: &Value) -> Result { let pos = style_index(d, &name)?; let nm = unique_name(&format!("{name} copy"), |n| d.graphic_style(n).is_some()); let g = GraphicStyle { name: nm.clone(), id: d.next_graphic_style_id(), ..d.graphic_styles[pos].clone() }; - d.graphic_styles.insert(pos + 1, g); + d.graphic_styles.push(g); Ok(nm) })?; Ok(json!({"name": new})) diff --git a/crates/engine/src/tests/styles.rs b/crates/engine/src/tests/styles.rs index e460aeb890..6f0242c662 100644 --- a/crates/engine/src/tests/styles.rs +++ b/crates/engine/src/tests/styles.rs @@ -151,6 +151,32 @@ fn style_names_are_unique() { assert_ne!(style(&s, "Y copy").id, style(&s, "Y").id); } +#[test] +fn duplicate_puts_the_copy_at_the_end_of_the_list_in_one_undo_step() { + let mut s = session(); + let a = rect(&mut s, 10.0); + run(&mut s, "graphicStyle.new", json!({"name": "S"})); + let names = |s: &Session| s.doc().unwrap().doc.graphic_styles.iter().map(|g| g.name.clone()).collect::>(); + let before = names(&s); + // A style that is not last: the copy still goes after every other style. + let first = before[0].clone(); + assert_ne!(first, *before.last().unwrap()); + assert_eq!(run(&mut s, "graphicStyle.duplicate", json!({"name": first}))["name"], format!("{first} copy")); + let after = names(&s); + assert_eq!(after[..before.len()], before[..]); + assert_eq!(after.last(), Some(&format!("{first} copy"))); + let (src, copy) = (style(&s, &first), style(&s, &format!("{first} copy"))); + assert_eq!(copy.appearance, src.appearance); + assert_ne!(copy.id, src.id); + // Nothing is linked to the copy, and the source keeps its links. + assert!(linked(&mut s, &format!("{first} copy")).is_empty()); + assert_eq!(linked(&mut s, "S"), vec![a.0]); + run(&mut s, "edit.undo", json!({})); + assert_eq!(names(&s), before); + assert!(s.execute("graphicStyle.duplicate", &json!({"name": "nope"})).is_err()); + assert_eq!(names(&s), before); +} + /// Three rectangles: `a` (the source of style "S"), `b` and `c`, all linked to "S". fn linked_three(s: &mut Session) -> (NodeId, NodeId, NodeId) { let a = rect(s, 10.0); diff --git a/crates/ui-egui/src/panels/graphic_styles.rs b/crates/ui-egui/src/panels/graphic_styles.rs index b99f9ec25b..e36eee0e9e 100644 --- a/crates/ui-egui/src/panels/graphic_styles.rs +++ b/crates/ui-egui/src/panels/graphic_styles.rs @@ -3,9 +3,10 @@ //! shows the shape outlined in black and filled with white, under a red slash. Clicking a style applies it to the //! selection (Alt-click adds it on top); Shift-click adds to the panel's selection every style from //! the last one clicked without Shift through this one; Cmd/Ctrl-click adds or removes one; -//! double-click opens Graphic Style Options. Dragging a style moves it in the list, or applies it -//! to the art it is dropped on (`canvas::panel_drop`); art dragged off the canvas or the Appearance -//! panel's thumbnail dropped on the panel becomes a new style. Holding the right button on a style +//! double-click opens Graphic Style Options. Dragging a style moves it in the list, applies it +//! to the art it is dropped on (`canvas::panel_drop`), or, dropped on New Graphic Style, adds a +//! copy of it and of the styles highlighted with it at the end of the list; art dragged off the +//! canvas or the Appearance panel's thumbnail dropped on the panel becomes a new style. Holding the right button on a style //! shows it large, on the selected object when there is one. The Control bar's Style picker lists //! the same tiles ([`picker`]). Graphic style libraries open in library panels //! ([`GraphicStyleLibraries`]). @@ -566,7 +567,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { None => tiles(app, ui, &shown, &sel, &mut ev), } }); - let zone = ui.interact(out.inner_rect, ui.scope_id().with("gs-drop"), Sense::hover()); + // The drop zone is the part of the list on screen: when the list shrinks to its rows, + // `inner_rect` reaches past it over the footer's buttons. + let zone = ui.interact(out.inner_rect.intersect(ui.min_rect()), ui.scope_id().with("gs-drop"), Sense::hover()); zone_input(ui, &zone, &doc, &mut ev); }); act(app, ui, &shown, ev, false); @@ -584,9 +587,14 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { app.run("graphicStyle.breakLink", json!({})).ok(); } ui.add_space((ui.available_width() - 2.0 * 28.0).max(0.0)); - if widgets::icon_button_enabled(ui, "dc-new-item", tl!("New Graphic Style (Alt-click to name it)"), false, has_sel, 24.0).clicked() { + // A style dragged from the list can be dropped on it, also with no art selected: the + // button is enabled while one is held. + let new_enabled = has_sel || dragged_style(ui.ctx(), &doc).is_some(); + let new = widgets::icon_button_enabled(ui, "dc-new-item", tl!("New Graphic Style (Alt-click to name it)"), false, new_enabled, 24.0); + if new.clicked() { new_style(app, alt_held(ui)); } + drop_on_new(app, ui, &new, &sel); if widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Graphic Style (Alt-click: without asking)"), false, !sel.is_empty(), 24.0) .clicked() { @@ -632,6 +640,55 @@ fn new_style(app: &mut VectorcraftApp, ask: bool) { } } +/// The style of `d` being dragged from the panel, if one is. +fn dragged_style(ctx: &egui::Context, d: &Document) -> Option { + match egui::DragAndDrop::payload::(ctx).as_deref() { + Some(PanelDrag::GraphicStyle(n)) if d.graphic_style(n).is_some() => Some(n.clone()), + _ => None, + } +} + +/// The styles a style dragged from the panel carries: every highlighted style (`sel`) in panel +/// order when the dragged style `name` is one of them, else that style alone. +fn carried(d: &Document, sel: &[String], name: &str) -> Vec { + if sel.iter().any(|s| s == name) { + d.graphic_styles.iter().filter(|g| sel.contains(&g.name)).map(|g| g.name.clone()).collect() + } else { + vec![name.to_string()] + } +} + +/// A style dragged onto New Graphic Style (`button`): the button is outlined while the style is +/// held over it, and on release the style, with the styles highlighted with it (`sel`), is +/// duplicated ([`duplicate`]). Other drags are left to their own targets. +fn drop_on_new(app: &mut VectorcraftApp, ui: &Ui, button: &Response, sel: &[String]) { + let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return }; + let Some(name) = dragged_style(ui.ctx(), &doc) else { return }; + if button.dnd_hover_payload::().is_none() { + return; + } + widgets::drop_target_outline(ui, button.rect); + if button.dnd_release_payload::().is_some() { + duplicate(app, ui.ctx(), &carried(&doc, sel, &name)); + } +} + +/// Duplicates `names` (`graphicStyle.duplicate`, each copy at the end of the list) in one undo +/// step and highlights the copies. A failure is shown in the status bar and changes nothing. +fn duplicate(app: &mut VectorcraftApp, ctx: &egui::Context, names: &[String]) { + let made = if let [name] = names { + app.run("graphicStyle.duplicate", json!({ "name": name })).map(|r| vec![r]) + } else { + let commands: Vec = names.iter().map(|n| json!({ "command": "graphicStyle.duplicate", "params": { "name": n } })).collect(); + app.run("command.batch", json!({ "label": "Duplicate Graphic Style", "commands": commands })) + .map(|r| r["results"].as_array().cloned().unwrap_or_default()) + }; + match made { + Ok(made) => set_pstate(ctx, "gs-sel", made.iter().filter_map(|r| r["name"].as_str().map(str::to_string)).collect::>()), + Err(e) => app.status(e), + } +} + /// Delete `names` after asking, or at once with `now` (Alt-click). fn delete(app: &mut VectorcraftApp, names: &[String], now: bool) { let params = json!({ "names": names }); @@ -1164,6 +1221,99 @@ mod tests { assert_eq!(d.node(rect).unwrap().extras().graphic_style, d.graphic_styles.last().map(|g| g.id)); } + /// A style dropped on New Graphic Style is duplicated at the end of the list, also with no art + /// selected; a highlighted style carries the other highlighted styles with it, in one undo step. + /// A style dropped on the Delete button is not moved in the list. + #[test] + fn a_style_dropped_on_new_graphic_style_is_duplicated_at_the_end() { + let mut app = app(); + app.run("select.none", json!({})).unwrap(); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + let screen = Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(260.0, 600.0))); + // One frame of the panel with `events`: the center of the footer button labeled `label` + // and whether it is enabled. + let button = |app: &mut VectorcraftApp, events: Vec, label: &str| { + let mut out = ctx.run_ui(egui::RawInput { screen_rect: screen, events, ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + let nodes = &out.platform_output.accesskit_update.as_ref().expect("accessibility tree").nodes; + let (_, node) = nodes.iter().find(|(_, n)| n.label() == Some(label)).unwrap_or_else(|| panic!("{label}")); + let b = node.bounds().expect("visible button"); + (pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32), !node.is_disabled()) + }; + let new_button = |app: &mut VectorcraftApp, events: Vec| button(app, events, "New Graphic Style (Alt-click to name it)"); + let release = |at: egui::Pos2| { + let up = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }; + vec![egui::Event::PointerMoved(at), up] + }; + let links = |app: &VectorcraftApp| { + app.session.active().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.extras().graphic_style).collect::>() + }; + let doc = |app: &VectorcraftApp| app.session.active().unwrap().doc.clone(); + for view in [View::SmallList, View::Thumbnail] { + app.ui.graphic_styles_view = view; + let n = names(&app); + let linked = links(&app); + // With no art selected the button is off until a style is held over it. + let (at, on) = new_button(&mut app, vec![]); + assert!(!on, "{view:?}: off with no art selected"); + egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[1].clone())); + let (_, on) = new_button(&mut app, vec![egui::Event::PointerMoved(at)]); + assert!(on, "{view:?}: on while a style is dragged"); + assert_eq!(names(&app), n, "{view:?}: holding it there changes nothing"); + // Released on it: a copy with the same look and a new id goes to the end, highlighted. + egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[1].clone())); + new_button(&mut app, release(at)); + let copy = format!("{} copy", n[1]); + assert_eq!(names(&app)[..n.len()], n[..], "{view:?}"); + assert_eq!(names(&app)[n.len()..], *std::slice::from_ref(©), "{view:?}"); + let d = doc(&app); + let (src, made) = (d.graphic_style(&n[1]).unwrap(), d.graphic_style(©).unwrap()); + assert_eq!(made.appearance, src.appearance); + assert_ne!(made.id, src.id); + assert_eq!(links(&app), linked, "{view:?}: no art is linked or unlinked"); + assert_eq!(selected(&ctx, &d), std::slice::from_ref(©)); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(names(&app), n, "{view:?}: one undo step"); + } + + // Two highlighted styles, one of them dragged: both are copied in panel order, in one step. + app.ui.graphic_styles_view = View::SmallList; + let n = names(&app); + let (at, _) = new_button(&mut app, vec![]); + set_pstate(&ctx, "gs-sel", vec![n[3].clone(), n[0].clone()]); + egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[3].clone())); + new_button(&mut app, release(at)); + let copies = [format!("{} copy", n[0]), format!("{} copy", n[3])]; + assert_eq!(names(&app)[n.len()..], copies); + assert_eq!(selected(&ctx, &doc(&app)), copies); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(names(&app), n, "the group's copies go in one undo step"); + app.run("edit.redo", json!({})).unwrap(); + assert_eq!(names(&app)[n.len()..], copies); + app.run("edit.undo", json!({})).unwrap(); + + // A style that is not highlighted is copied alone. + set_pstate(&ctx, "gs-sel", vec![n[3].clone(), n[0].clone()]); + egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[2].clone())); + new_button(&mut app, release(at)); + assert_eq!(names(&app)[n.len()..], [format!("{} copy", n[2])]); + app.run("edit.undo", json!({})).unwrap(); + + // Other drags dropped on the button make nothing. + let rect = doc(&app).layers[0].children().unwrap()[0].id; + for payload in [PanelDrag::Art(vec![rect]), PanelDrag::Appearance(rect), PanelDrag::GraphicStyle("No such style".into())] { + egui::DragAndDrop::set_payload(&ctx, payload); + new_button(&mut app, release(at)); + assert_eq!(names(&app), n); + } + // A style dropped on the Delete button below the list is not moved in the list. + let (trash, _) = button(&mut app, vec![], "Delete Graphic Style (Alt-click: without asking)"); + egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[1].clone())); + button(&mut app, release(trash), "Delete Graphic Style (Alt-click: without asking)"); + assert_eq!(names(&app), n); + } + #[test] fn shift_click_selects_a_range_and_cmd_click_adds_or_removes_one_style() { let mut app = app(); diff --git a/docs/mcp.md b/docs/mcp.md index c7aa202d3f..7ea18fbb29 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4261,7 +4261,9 @@ style is applied to gets them at the same place relative to its own bounds. `graphicStyle.merge {names, name?}` adds a style stacking the fills, strokes and effects of two or more styles (each on top of the ones before it) with the first one's transparency; `graphicStyle.move {name, to}` reorders the -list (what dragging a style in the panel does). Override Character Color (`graphicStyle.setOptions +list (what dragging a style in the panel does). `graphicStyle.duplicate {name}` adds a copy of the style at the end +of the list, named ` copy` (` copy 2` and so on when that is taken), with no object linked to it; the +panel menu's Duplicate Graphic Style and a style dropped on the panel's New Graphic Style button run it. Override Character Color (`graphicStyle.setOptions {overrideCharColor}`, the preference `overrideCharColor`, on by default) makes a style applied to type replace its characters' fill and stroke with the style's fills and strokes; off, the characters keep their colour under them. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index b4bda6f151..d5b1378850 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1759,6 +1759,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Graphic styles:** styles keep opacity and blend mode, capture groups and type, apply on top with Alt, and link to the objects using them; Redefine, Break Link, Graphic Style Options, Select All Unused, Sort by Name, and Select > Same Graphic Style / Appearance Attribute. The panel has list and thumbnail views with rendered previews, merge, reorder and drag and drop, plus a Control bar Style picker; eleven generated style libraries (including Game HUD, Status Effects, Neon & Glow, Painted and Sketched, whose seven styles each repaint a solid fill with one watercolor, dry brush, pastel, charcoal or ink effect, and Textures) save and load as `.vcstyles`. The built-in Textures graphic style library (`graphicStyle.addFromLibrary {library: "textures"}`) has eight styles that paint their fills and strokes with the texture effects: Fine Grain (Grain), Canvas Weave and Burlap Sack (Texturizer), Cracked Glaze (Craquelure), Mosaic Floor (Mosaic Tiles), Quilted Squares (Patchwork), Leaded Glass (Stained Glass) and Damp Paper (Water Paper). The help page names new graphic styles for textures ([What's new](https://helpx.adobe.com/illustrator/desktop/new-features/whats-new.html)) without naming them, so the styles, their names and their settings are VectorCraft's own (`tests::stylelib::textures_styles_apply_their_texture_effects_and_keep_their_params_through_save_and_open`). In the Graphic Styles panel, Shift-click selects a range of styles and Ctrl/Cmd-click adds or removes one. + A graphic style dragged onto the Graphic Styles panel's New Graphic Style button is duplicated, as the panel menu's Duplicate Graphic Style does, and both put the copy at the end of the list, as the help page describes ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=391)). VectorCraft's own rules: the button takes the drop with no art selected; a dragged style that is highlighted brings the other highlighted styles, copied in panel order in one undo step, and the copies are highlighted; the copy is named ` copy`, with a number when that is taken, and no art is linked to it (`a_style_dropped_on_new_graphic_style_is_duplicated_at_the_end` in `crates/ui-egui/src/panels/graphic_styles.rs`, `tests::styles::duplicate_puts_the_copy_at_the_end_of_the_list_in_one_undo_step`). In the Graphic Styles panel's thumbnail and list views, a style with no fill and no stroke, one with only effects or transparency included, shows its preview shape with a black outline, a white fill and a red slash, as the help page describes for the panel's thumbnails ([Graphic styles](https://helpx.adobe.com/illustrator/using/graphic-styles.html)); its effects still draw on that shape. The Control bar's Style picker and chip, graphic style library panels and the large preview on the selected object show the same marker. A fill or stroke row that paints None does not count as a fill or stroke, and a hidden row or one with zero opacity does; these rules, the marker outside the panel's thumbnails and the slash's direction and size are VectorCraft's own (`a_style_with_no_fill_and_no_stroke_shows_an_outlined_shape_and_a_red_slash` in `crates/ui-egui/src/panels/graphic_styles.rs`). Applying a style to several objects, and Redefine Graphic Style, give the objects one shared copy of the style's appearance instead of a copy each; an object that is edited later gets its own copy, and an object whose placed gradients are fitted to its own bounds gets its own. The undo history's memory estimate counts a shared appearance once. Saved files are unchanged (`crates/engine/src/tests/styles.rs`). - **Several text styles at once:** in the Character Styles and Paragraph Styles panels, Shift-click highlights a range of styles and Ctrl/Cmd-click adds or removes one, without applying them; the panel menu's Select All Unused (`charStyle.unused`, `paraStyle.unused`) highlights the styles no type uses (in the layers, opacity masks, symbols, graph designs, pattern tiles and the art of brushes), never the Normal style; Delete, the button or the menu item, deletes every highlighted style but Normal in one undo step (`charStyle.delete {names}`, `paraStyle.delete {names}`). The menu's Duplicate copies every highlighted style in one undo step and highlights the copies. A highlighted row dragged onto Create New Style or Delete carries every highlighted style: dropped on Create New Style it copies them all and highlights the copies, and dropped on Delete it deletes them all but Normal and clears the highlight; a row from outside the highlight carries only its own style. Public reference: [Character and paragraph styles](https://web.archive.org/web/20261015081534/https://helpx.adobe.com/illustrator/using/character-paragraph-styles.html).