diff --git a/crates/engine/src/cmd/swatch.rs b/crates/engine/src/cmd/swatch.rs index 28885a1123..8a8a2cfccf 100644 --- a/crates/engine/src/cmd/swatch.rs +++ b/crates/engine/src/cmd/swatch.rs @@ -75,7 +75,7 @@ pub fn specs() -> Vec { "Add Used Colors", ["Window", "Swatches"], None, - "{selection?: false (only the selected art's colours; default: all the art's), global?: false (the new swatches are global and the matching unlinked colours in that art link to them)} add a swatch for each colour used (fills, strokes, text, gradient stops, mesh points) that no solid swatch has yet, as one undo step (none when there is no new color; the Swatches panel menu's Add Selected Colors sends selection and global) → {added: [names], linked}", + "{selection?: false (only the selected art's colours; default: all the art's), global?: false (the new swatches are global and the matching unlinked colours in that art link to them)} add a swatch for each colour used (fills, strokes, text, gradient stops, mesh points) that no solid swatch has yet, as one undo step (none when there is no new color; the Swatches panel menu's Add Selected Colors sends selection and global; with Global Edit on, the other members keep their colors) → {added: [names], linked}", has_doc, swatch_add_used ), @@ -1048,12 +1048,17 @@ fn swatch_add_used(s: &mut Session, p: &Value) -> Result { } Ok(ids) }; + // Typing in progress is its own undo step and is in the document the colors are read from. + super::variablecmds::settle_typing(s)?; // With no new color there is nothing to add or link, so no edit and no undo step. let st = s.doc()?; if new_used_colors(&st.doc, &used_ids(&st.doc, &st.selection)?).is_empty() { return Ok(json!({"added": [], "linked": 0})); } - let (added, linked) = s.edit("Add Used Colors", |d, sel| { + // Linking a paint to its new swatch keeps its color, so Global Edit gives the link to no other + // member: a member whose color differs keeps it. + let global_edit = s.doc_mut()?.global_edit.take(); + let edited = s.edit("Add Used Colors", |d, sel| { let ids = used_ids(&*d, &*sel)?; let colors = new_used_colors(d, &ids); let mut free = d.free_swatch_names(); @@ -1065,7 +1070,9 @@ fn swatch_add_used(s: &mut Session, p: &Value) -> Result { } let linked = if global { link_colors(d, &ids, &links) } else { 0 }; Ok((links.into_iter().map(|(_, n)| n).collect::>(), linked)) - })?; + }); + s.doc_mut()?.global_edit = global_edit; + let (added, linked) = edited?; Ok(json!({"added": added, "linked": linked})) } diff --git a/crates/engine/src/tests/swatchcmds.rs b/crates/engine/src/tests/swatchcmds.rs index 0ac3ee7ed0..f043ae08ae 100644 --- a/crates/engine/src/tests/swatchcmds.rs +++ b/crates/engine/src/tests/swatchcmds.rs @@ -146,6 +146,48 @@ fn add_used_colors_with_no_new_color_records_no_undo_step() { assert_eq!(undo_len(&s), undo); } +/// A run that finds no new color, while the Type tool is typing, still ends the typing session: the +/// typing is its own undo step. +#[test] +fn add_used_colors_with_no_new_color_ends_the_typing() { + use vectorcraft_tools::{PointerEvent, PointerKind}; + let mut s = session(); + let v = ViewInfo::default(); + let t = NodeId(run(&mut s, "text.create", json!({"x": 10, "y": 10, "text": "Hello"}))["id"].as_u64().unwrap()); + run(&mut s, "swatch.addUsedColors", json!({})); + s.select_tool("type", v).unwrap(); + let b = doc(&s).bounds_of(&[t], false).unwrap(); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, b.x1 - 1.0, b.center().y), v).unwrap(); + } + s.tool_text("!", v).unwrap(); + assert!(crate::cmd::typing_in_progress(&s)); + let steps = undo_len(&s); + assert_eq!(run(&mut s, "swatch.addUsedColors", json!({})), json!({"added": [], "linked": 0})); + assert!(!crate::cmd::typing_in_progress(&s)); + let labels: Vec = s.doc().unwrap().history.undo.iter().map(|e| e.label.clone()).collect(); + assert_eq!((labels.len(), labels.last().map(String::as_str)), (steps + 1, Some("Typing"))); +} + +/// Add Selected Colors while Global Edit is on links only the selected art: a member of the same +/// shape with another color keeps its color and stays unlinked, and Global Edit stays on. +#[test] +fn add_selected_colors_in_global_edit_keeps_the_other_members_colors() { + let mut s = session(); + let a = rect_filled(&mut s, json!({"color": "#123456"})); + let b = rect_filled(&mut s, json!({"color": "#654321"})); + run(&mut s, "select.set", json!({"ids": [a.0]})); + let r = run(&mut s, "select.globalEdit", json!({})); + assert_eq!((r["active"].clone(), r["ids"].clone()), (json!(true), json!([a.0, b.0])), "the other rectangle is a member"); + let other = fill(&s, b); + let undo = undo_len(&s); + run(&mut s, "swatch.addUsedColors", json!({"selection": true, "global": true})); + assert!(matches!(fill(&s, a), Paint::Solid { swatch: Some(_), .. }), "{:?}", fill(&s, a)); + assert_eq!(fill(&s, b), other, "the unselected member keeps its color"); + assert_eq!(undo_len(&s), undo + 1); + assert!(s.doc().unwrap().global_edit.is_some(), "Global Edit stays on"); +} + /// Give `id` the fill `p` exactly as written (a command would round or convert some colors). fn set_fill(s: &mut Session, id: NodeId, p: Paint) { std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(id).unwrap().appearance.set_fill(p); diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index d173e6b2a7..61756f633e 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -1421,6 +1421,15 @@ fn click_menu_item(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) { menu_frame(app, ctx, vec![button(false)]); } +/// Whether the panel menu's item `label` is enabled, as the accessibility tree reports it. +fn menu_item_enabled(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) -> bool { + ctx.enable_accesskit(); + let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(236.0, 700.0))), ..Default::default() }; + let mut out = ctx.run_ui(raw, |ui| menu(app, ui)); + out.textures_delta.clear(); + footer_button(&out, label).1 +} + /// The panel menu's Show Recent Colors hides and shows the panel's Recent Colors row (#6617): /// checked by default, applied colors still join the list while the row is hidden, and the Color /// panel keeps its own row and setting. @@ -1583,10 +1592,12 @@ fn add_selected_colors_adds_the_selection_colors_as_global_swatches() { let undo = |app: &VectorcraftApp| app.session.active().unwrap().history.undo.len(); app.run("select.set", json!({"ids": []})).unwrap(); let (before, steps) = (app.session.active().unwrap().doc.clone(), undo(&app)); + assert!(!menu_item_enabled(&mut app, &ctx, "Add Selected Colors"), "off with nothing selected"); click_menu_item(&mut app, &ctx, "Add Selected Colors"); assert_eq!(app.session.active().unwrap().doc, before, "off with nothing selected"); assert_eq!(undo(&app), steps); app.run("select.set", json!({"ids": [picked]})).unwrap(); + assert!(menu_item_enabled(&mut app, &ctx, "Add Selected Colors"), "on with art selected"); let (before, steps) = (app.session.active().unwrap().doc.clone(), undo(&app)); click_menu_item(&mut app, &ctx, "Add Selected Colors"); let doc = &app.session.active().unwrap().doc; diff --git a/docs/mcp.md b/docs/mcp.md index 616fa82447..0f09dba6cd 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1100,7 +1100,7 @@ them in the Swatches panel does); give colour group names instead to reorder the in the app runs `paint.setFill` (or `paint.setStroke`, the active proxy) with `ids: [the object under the pointer]`. The Swatches panel menu's commands: `swatch.addUsedColors {selection?, global?}` (Add Used Colors sends `{}`; Add Selected Colors, on while art is selected, sends `{selection: true, global: true}`; a run with no new color records no -undo step), `swatch.unused` (a query: the +undo step; with Global Edit on, the other members keep their colors), `swatch.unused` (a query: the names Select All Unused selects; a spot swatch counts as used while an image placed from a DCS file has a plate of its ink), `swatch.merge {names}` (the first is kept; gradient stops linked to the others drop their process plates), `swatch.ungroup {name}` and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 07b25adf60..28fee7e34b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1862,7 +1862,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Swatches:** names follow the colour model and are unique; Swatch Options (process/spot, Global, Gray/RGB/HSB/CMYK/Web, live preview); editing a global or spot swatch recolours every linked fill, stroke and text run in one undo step; multi-select and delete with confirmation; New Swatch and New Color Group dialogs (a group from the selected artwork's colours); swatches in colour groups convert, separate and count like any other. The Swatches panel selects ranges and whole groups, has a find field, and drags swatches to reorder, regroup or paint art; Add Used Colors, Select All Unused, Merge, Ungroup and Sort by Kind; a CMYK document keeps applied colours in CMYK. Swatch libraries: nine generated colour libraries, seven gradient libraries (among them Organic Fades, soft perceptually mixed multi-stop fades that thin out to transparent, and Holographic, seven opaque linear foils of narrow pastel and pearl bands and seven radial glows that fade out to a clear edge) and three pattern libraries (Geometric Patterns; Grit Textures with eight seamless grain, speckle, stipple, scratch and fleck tiles; and Optical Effects with eight of VectorCraft's own seamless wave, ring, warped-check, stripe, chevron and lens tiles; their swatches bring their patterns) in a library panel, saved as `.vcswatches`, `.gpl`, swatch exchange (`.ase`) or CSS, and loaded from `.vcswatches`, `.gpl` and `.ase` files (`.ase` both ways: RGB, CMYK, Lab and Gray; global, spot and process; groups) and from color books (`.acb`, read only: the RGB, CMYK or Lab colors of a book such as a Pantone book a user owns, named with its prefix and suffix, spot unless it says process, #831); `swatch.library.copyToUser` copies a loaded library into the User Defined folder without replacing a file, and a file with the same extension and bytes as a User Defined library opens as that library. Tints of global and spot colours ("Name 40%") stay linked and separate as a percentage of their plate. Spot colours can be defined in Lab (Spot Colors options). A built-in [Registration] swatch prints on every plate. Right-clicking a swatch in either list or thumbnail view selects it without applying paint and offers Swatch Options…, Duplicate Swatch and Delete Swatch for that item. None, [Registration] and missing swatches disable these actions. Existing active-item multiselection is retained; actions still target only the clicked item. Evidence: `panels::swatches::tests::context_menu` harness tests cover all five views, selection, dialog dispatch, duplicate/delete and Undo. All 39 Swatches tests pass; the regression fails with the menu hooks removed. Rendered headless list and thumbnail menus were inspected, and a fresh local deep CodeRabbit review reported zero findings. Full workspace CI passed on Linux/WSL on the merged branch (all 13 gates), including the test-helper correction for the upstream compile error tracked in #7727; native Windows full CI has two unchanged engine-test failures. Scores and estimates unchanged. Validation on 2026-11-15: native Windows formatting, workspace Clippy and all 39 focused Swatches tests passed. Windows full CI stopped at unchanged engine tests `tests::package::a_confined_package_names_files_outside_the_read_root_by_name` (slash-sensitive report assertion) and `tests::plugins::plugin_storage_behind_a_link_is_left_alone` (storage-link setup returned AlreadyExists). Both cases pass in the Linux/WSL full CI run, which passed all 13 gates. No engine or CI workflow changes are included. - The Swatches panel menu has Add Selected Colors, on while art is selected: it adds a swatch for each color of the selected art that the panel does not hold yet, as global swatches the art's matching paints link to, in one undo step ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/add-colors-to-swatches.html) describes the panel menu command that adds the selected artwork's colors). The swatch names and the colors it reads (fills, strokes, text, gradient stops, mesh points) are VectorCraft's own, as for Add Used Colors. Add Used Colors and Add Selected Colors record no undo step when there is no new color. Evidence: `add_selected_colors_adds_the_selection_colors_as_global_swatches` in `crates/ui-egui/src/panels/swatches/tests.rs`; `add_used_colors_with_no_new_color_records_no_undo_step` in `crates/engine/src/tests/swatchcmds.rs`. + The Swatches panel menu has Add Selected Colors, on while art is selected: it adds a swatch for each color of the selected art that the panel does not hold yet, as global swatches the art's matching paints link to, in one undo step ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/add-colors-to-swatches.html) describes the panel menu command that adds the selected artwork's colors). The swatch names and the colors it reads (fills, strokes, text, gradient stops, mesh points) are VectorCraft's own, as for Add Used Colors. Add Used Colors and Add Selected Colors record no undo step when there is no new color, and still end typing in progress as its own step. With Global Edit on, the members the command does not read keep their colors. Evidence: `add_selected_colors_adds_the_selection_colors_as_global_swatches` in `crates/ui-egui/src/panels/swatches/tests.rs`; `add_used_colors_with_no_new_color_records_no_undo_step`, `add_used_colors_with_no_new_color_ends_the_typing` and `add_selected_colors_in_global_edit_keeps_the_other_members_colors` in `crates/engine/src/tests/swatchcmds.rs`. The panel's Delete Swatch and Swatch Options (footer buttons and panel menu), New Color Group and Save Swatch Library treat only None and [Registration] as reserved, so a user swatch or color group whose name starts with `[` can be deleted, edited, grouped and saved; selected names the document no longer holds are left out (`panels::swatches::tests::bracketed_user_swatches_and_groups_can_be_deleted_and_edited`). Dragging swatches onto Delete Swatch deletes them ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=136), Replace, merge, or delete swatches section, lists this drag as one of the ways to delete the selected swatches): a swatch or color group dragged from the Swatches panel, in any view, and released on the Delete Swatch button is deleted through `swatch.delete`, even while nothing was selected and the button is disabled for clicks. A swatch that is part of the selection carries the other selected swatches of its kind with it. VectorCraft's own rules: the drop asks first as a plain click does, and Alt does not skip the question; Cancel keeps everything, and OK deletes them in one undo step; None and [Registration] are never taken; the button is enabled while swatches are selected or while a swatch or group of the active document is being dragged, and it is outlined only while such a swatch or group is held over it, so a paint from another panel, art and a swatch dragged from another document delete nothing. Tests: `panels::swatches::tests::swatches_dropped_on_delete_swatch_are_deleted_after_asking`, `delete_swatch_ignores_other_drags`. Dragging swatches onto New Swatch duplicates them ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/duplicate-swatches.html) gives this drag as another way to duplicate the selected swatches): a swatch dragged from the Swatches panel, in any view, and released on the New Swatch button is copied through `swatch.duplicate` without opening the New Swatch dialog. A swatch that is part of the selection carries the other selected swatches with it. VectorCraft's own rules: each copy goes just after its swatch and in its color group, named ` copy` and then ` copy 2`; the copies of one drop are one undo step and are selected; modifiers held on release do not change the drop; color groups, None and [Registration] are not duplicated; the button is outlined only while such a swatch of the active document is held over it, so a paint from another panel, art, a swatch dragged from another document and a swatch deleted during the drag duplicate nothing. Tests: `panels::swatches::tests::swatches_dropped_on_new_swatch_are_duplicated`, `new_swatch_ignores_other_drags`.