diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index a519986ed0..f2444bc019 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1096,7 +1096,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorPicker", "Color Picker…", "", - "{stroke?: bool (default: the active proxy), artboard?: index (the picker is for that artboard's background color instead), color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray} (default: the proxy's color, or the artboard's color, white when it has none)} open the Color Picker (fields: hex or color, channel, webOnly, swatches); RGB, HSB and hex values use the working RGB space; OK runs paint.setFill / paint.setStroke, or artboard.setProps {index, color} for an artboard", + "{stroke?: bool (default: the active proxy), artboard?: index (the picker is for that artboard's background color instead), color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray} (default: the proxy's color, or the artboard's color, white when it has none)} open the Color Picker (fields: hex or color, channel, webOnly, swatches); RGB, HSB and hex values use the working RGB space; OK runs paint.setFill / paint.setStroke, or artboard.setProps {index, color} for an artboard. Artboard preview and OK require the opening document to be active", ), ( "ui.sampleScreenColor", diff --git a/crates/ui-egui/src/dialogs/color_picker.rs b/crates/ui-egui/src/dialogs/color_picker.rs index e0ad66addf..f9649382bf 100644 --- a/crates/ui-egui/src/dialogs/color_picker.rs +++ b/crates/ui-egui/src/dialogs/color_picker.rs @@ -3,7 +3,7 @@ //! as one undo step through `paint.setFill` / `paint.setStroke` and makes the colour the Color //! Guide's base colour; Cancel puts the art back. Opened for an artboard (Properties › Artboards › //! Fill), it shows the colour on the artboard's paper and OK keeps it through -//! `artboard.setProps {index, color}`. +//! `artboard.setProps {index, color}`. Preview and OK require the opening document to be active. //! //! A command dialog's colour row raises a `ColorRequest`; [`pump`] opens a picker over that dialog //! and answers the row with its OK. Every picker has the Color Swatches view; one over Recolor @@ -43,11 +43,18 @@ pub(crate) enum Target { /// The stroke proxy. Stroke, /// The background colour of this artboard. - Artboard(usize), + Artboard { document: u64, index: usize }, /// A colour row `key` of the open dialog `parent`. Answer { parent: DialogId, key: String }, } +impl Target { + fn in_active_document(&self, app: &VectorcraftApp) -> bool { + let Self::Artboard { document, .. } = self else { return true }; + app.session.active().is_some_and(|st| st.uid == *document) + } +} + /// One open Color Picker: what the dialog itself does not know. pub(crate) struct Open { /// The dialog's id on the window's host. @@ -150,14 +157,17 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { None | Some(Value::Null) => None, Some(v) => { let index = v.as_u64().and_then(|i| usize::try_from(i).ok()); - let found = index.and_then(|i| Some((i, app.session.active()?.doc.artboards.get(i)?.color))); - let (i, color) = found.ok_or("no such artboard")?; - Some((i, color.unwrap_or(Color::WHITE))) + let found = index.and_then(|i| { + let st = app.session.active()?; + let color = st.doc.artboards.get(i)?.color.unwrap_or(Color::WHITE); + Some((st.uid, i, color)) + }); + Some(found.ok_or("no such artboard")?) } }; let color = match (p.get("color"), artboard) { (Some(v), _) => color_value(v).ok_or_else(|| format!("bad color {v}"))?, - (None, Some((_, c))) => c, + (None, Some((_, _, c))) => c, (None, None) => proxy_color(app, stroke), }; let dialogs = app.dialogs().ok_or("no window")?; @@ -184,9 +194,9 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { if matches!(color, Color::Cmyk { .. } | Color::Lab { .. }) { dialog = dialog.kept(model_values(&color)); } - // PLAN: assumed the dialog's own `instance` keeps artboards apart; the host replaces a picker only for the same target. - if let Some((i, _)) = artboard { - dialog = dialog.instance(i); + // The host replaces a picker only for the same document and artboard. + if let Some((document, index, _)) = artboard { + dialog = dialog.instance((document, index)); } let id = dialogs.with(|h| h.open(dialog)); // A picker the open replaced leaves its preview behind: end it. @@ -196,7 +206,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { let _ = app.session.cancel_interaction(); } let target = match artboard { - Some((i, _)) => Target::Artboard(i), + Some((document, index, _)) => Target::Artboard { document, index }, None if stroke => Target::Stroke, None => Target::Fill, }; @@ -274,6 +284,13 @@ fn finish( open: &mut Open, result: Option>, ) { + // Switching documents rolls back the source preview. Do not settle it against the new drawing. + if !open.target.in_active_document(app) { + if matches!(result, Some(DialogResult::Ok(_))) { + app.status("The active document changed while the Color Picker was open"); + } + return; + } let preview = std::mem::take(&mut open.preview); match (result, &open.target) { (Some(DialogResult::Ok(r)), Target::Answer { parent, key }) => { @@ -293,7 +310,7 @@ fn finish( /// The command that applies colour `c` to the picker's target, and its params. fn paint_command(target: &Target, c: Color) -> (&'static str, Value) { match target { - Target::Artboard(i) => ("artboard.setProps", json!({ "index": i, "color": color_json(&c) })), + Target::Artboard { index, .. } => ("artboard.setProps", json!({ "index": index, "color": color_json(&c) })), Target::Stroke => ("paint.setStroke", json!({ "color": color_json(&c) })), Target::Fill | Target::Answer { .. } => ("paint.setFill", json!({ "color": color_json(&c) })), } @@ -314,18 +331,18 @@ fn in_document_model(app: &VectorcraftApp, c: Color) -> Color { /// then only becomes the default paint, on OK). An artboard shows it with or without a selection. fn preview(app: &mut VectorcraftApp, open: &mut Open, picked: &PickedColor) { // A picker over a command dialog only fills a row; the dialog previews it. - if matches!(open.target, Target::Answer { .. }) { + if matches!(open.target, Target::Answer { .. }) || !open.target.in_active_document(app) { return; } let (cmd, params) = paint_command(&open.target, in_document_model(app, color_of(picked))); let untouched = !app.session.in_interaction() && picked.color == open.start; - let artboard = matches!(open.target, Target::Artboard(_)); + let artboard = matches!(open.target, Target::Artboard { .. }); let selected = artboard || app.session.active().is_some_and(|st| !st.selection.objects.is_empty()); if untouched || !selected { return; } let label = match open.target { - Target::Artboard(_) => "Artboard Options", + Target::Artboard { .. } => "Artboard Options", Target::Stroke => "Stroke Color", _ => "Fill Color", }; @@ -342,7 +359,7 @@ fn commit(app: &mut VectorcraftApp, open: &Open, preview: LivePreview, picked: & let (cmd, params) = paint_command(&open.target, c); preview.commit(app, cmd, params)?; // A color picked for the fill or stroke also becomes the Color Guide's base color. - if !matches!(open.target, Target::Artboard(_)) { + if !matches!(open.target, Target::Artboard { .. }) { crate::panels::color_guide::choose_base(app, c); } Ok(()) diff --git a/crates/ui-egui/src/dialogs/color_picker/tests.rs b/crates/ui-egui/src/dialogs/color_picker/tests.rs index 47b1ad268f..26e3bf486b 100644 --- a/crates/ui-egui/src/dialogs/color_picker/tests.rs +++ b/crates/ui-egui/src/dialogs/color_picker/tests.rs @@ -52,6 +52,15 @@ fn artboard_color(app: &VectorcraftApp) -> Option { app.session.doc().unwrap().doc.artboards[1].color } +fn two_documents_with_artboards() -> (VectorcraftApp, egui::Context) { + let (mut app, ctx) = app(); + app.run("artboard.new", json!({})).unwrap(); + app.run("file.new", json!({"width": 300, "height": 300})).unwrap(); + app.run("artboard.new", json!({})).unwrap(); + app.run("document.activate", json!({"index": 0})).unwrap(); + (app, ctx) +} + /// The selected art takes each colour as it is picked; OK keeps the last as one undo step and /// Cancel puts the art back. #[test] @@ -101,6 +110,71 @@ fn an_artboard_shows_its_background_color_live() { assert!(app.run("ui.colorPicker", json!({"artboard": 9})).is_err()); } +#[test] +fn the_artboard_picker_previews_only_in_its_opening_document() { + let (mut app, ctx) = two_documents_with_artboards(); + app.run("ui.colorPicker", json!({"artboard": 1})).unwrap(); + set_hex(&mut app, &ctx, "#ff0000"); + assert_eq!(artboard_color(&app).map(|c| c.to_hex()).as_deref(), Some("#ff0000")); + + app.run("document.activate", json!({"index": 1})).unwrap(); + let before = undo_len(&app); + set_hex(&mut app, &ctx, "#00ff00"); + assert_eq!(artboard_color(&app), None, "the other document never previews the color"); + assert!(!app.session.in_interaction()); + assert_eq!(undo_len(&app), before); + + app.run("document.activate", json!({"index": 0})).unwrap(); + assert_eq!(artboard_color(&app), None, "leaving the source rolled its preview back"); + let before = undo_len(&app); + ok(&mut app, &ctx); + assert_eq!(artboard_color(&app).map(|c| c.to_hex()).as_deref(), Some("#00ff00")); + assert_eq!(undo_len(&app), before + 1); +} + +#[test] +fn confirming_an_artboard_picker_in_another_document_leaves_both_unchanged() { + let (mut app, ctx) = two_documents_with_artboards(); + let source_undo = undo_len(&app); + app.run("ui.colorPicker", json!({"artboard": 1, "color": "#00ff00"})).unwrap(); + frame(&mut app, &ctx); + app.run("document.activate", json!({"index": 1})).unwrap(); + let destination_undo = undo_len(&app); + ok(&mut app, &ctx); + assert_eq!(app.ui.status, "The active document changed while the Color Picker was open"); + assert_eq!(artboard_color(&app), None); + assert_eq!(undo_len(&app), destination_undo); + + app.run("document.activate", json!({"index": 0})).unwrap(); + assert_eq!(artboard_color(&app), None); + assert_eq!(undo_len(&app), source_undo); +} + +#[test] +fn canceling_an_artboard_picker_preserves_the_other_documents_interaction() { + let (mut app, ctx) = two_documents_with_artboards(); + app.run("ui.colorPicker", json!({"artboard": 1})).unwrap(); + set_hex(&mut app, &ctx, "#ff0000"); + app.run("document.activate", json!({"index": 1})).unwrap(); + app.begin_interaction("Other edit").unwrap(); + app.session.preview("artboard.setProps", &json!({"index": 1, "color": "#445566"})).unwrap(); + + cancel(&mut app, &ctx); + assert!(app.session.in_interaction(), "the current document keeps its own interaction"); + assert_eq!(artboard_color(&app).map(|c| c.to_hex()).as_deref(), Some("#445566")); +} + +#[test] +fn artboard_pickers_for_the_same_index_in_different_documents_have_separate_instances() { + let (mut app, _) = two_documents_with_artboards(); + app.run("ui.colorPicker", json!({"artboard": 1})).unwrap(); + let first = id(&app); + app.run("document.activate", json!({"index": 1})).unwrap(); + app.run("ui.colorPicker", json!({"artboard": 1})).unwrap(); + assert_ne!(id(&app), first); + assert_eq!(app.color_dialogs.pickers.len(), 2); +} + /// OK on an untouched picker for an artboard without a color leaves it without one and adds no /// undo step; a white the opener passes as `color` is set. #[test] diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 4da3dcdc16..e4d6d5d1c1 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1097,7 +1097,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorPicker", "Color Picker…", "", - "{stroke?: bool (default: the active proxy), artboard?: index (the picker is for that artboard's background color instead), color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray} (default: the proxy's color, or the artboard's color, white when it has none)} open the Color Picker (fields: hex or color, channel, webOnly, swatches); RGB, HSB and hex values use the working RGB space; OK runs paint.setFill / paint.setStroke, or artboard.setProps {index, color} for an artboard", + "{stroke?: bool (default: the active proxy), artboard?: index (the picker is for that artboard's background color instead), color?: \"#rrggbb\"|[r,g,b]|{c,m,y,k}|{gray} (default: the proxy's color, or the artboard's color, white when it has none)} open the Color Picker (fields: hex or color, channel, webOnly, swatches); RGB, HSB and hex values use the working RGB space; OK runs paint.setFill / paint.setStroke, or artboard.setProps {index, color} for an artboard. Artboard preview and OK require the opening document to be active", ), ( "ui.sampleScreenColor", diff --git a/docs/mcp.md b/docs/mcp.md index 23ae47a328..ccdc8fe6d6 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -10194,6 +10194,7 @@ layer of its own below the others; files that carry the editing data (Preserve E Export for Screens) keep it as the artboard's color, not as art. `includeArtboardFill: false` on `document.export`, `document.serialize`, `document.exportForScreens` (Include Artboard Fill) or `file.print` leaves it out. `inspect_document` lists it as the artboard's `color` (`#rrggbb`), and `ui.colorPicker {artboard: index}` opens the Color Picker for it. +The artboard preview and confirmation require the opening document to be active. Artboard Options' Show Center Mark and Show Cross Hairs: `artboard.setProps {index, showCenterMark?: bool, showCrossHairs?: bool}` (or each entry of `artboards`) turns them on or off for that artboard in one undo step, and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index e365c52b91..a0a60481fb 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -970,7 +970,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **A clip group in Properties:** with one clip group selected, the panel has Edit Clipping Path and Edit Contents at its top, under the Clip Group heading, which select the clipping path or the clipped art for the selection tools to transform alone, as Object › Clipping Mask does (: with a clip group selected, the tutorial uses Edit Clipping Path at the top of the Properties panel to select the mask for editing, and uses Edit Contents to select the masked art). Edit Contents shows only when the group clips something. Not checked against the reference app: whether Properties keeps the buttons while the clipping path or the contents is selected; the Control bar has no clip-group buttons here. Evidence: `panels::properties::tests::one_clip_group_has_edit_clipping_path_and_edit_contents_at_the_top`. - **Contextual controls in Properties:** the [Properties panel overview](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/properties-panel-overview.html) lists controls that appear for particular selections and tools; Properties has them, each running the existing command. Quick Actions has Blend Options for one selected blend, with the Blend tool or any other, as the [blending page](https://helpx.adobe.com/illustrator/using/blending-objects.html) describes (#4817) (the Blend Options dialog, OK one undo step) and Merge Live Paint when a Live Paint group is selected with more paths and nothing Live Paint refuses (`livePaint.merge`). Appearance has the stroke's Variable Width Profile list, the Control bar's, with the Width tool or when the stroke has a variable width (`stroke.set {profile}`), and beside fx the Delete icon: with one effect on the one selected object (its own or a fill's or stroke's) its name and an icon that removes it (`effect.remove`), with several an icon that opens the Appearance panel, as the overview describes. With Direct Selection and corners of one path selected, Corner and Corner Radius set the kind and radius of those corners (`object.setLiveShape`); a live rectangle's and polygon's own rows already do. Each edit is one undo step. The overview's Variable Font icon was already in Character. Not checked against the reference app: whether Merge needs two Live Paint groups (the overview speaks of several selected groups; `livePaint.merge` takes a group and paths), and where exactly each control sits in its section. Evidence: `panels::properties::tests::{blend_options_is_a_quick_action_for_one_blend_with_the_blend_tool, merge_live_paint_is_a_quick_action_for_a_live_paint_group_and_more, the_width_profile_shows_for_a_variable_width_or_the_width_tool, direct_selected_corners_show_their_kind_and_radius, one_effect_has_a_delete_icon_in_appearance}`. - **Edit Artboards in Properties:** a Transform section comes first (#5219): the reference point the Transform panel and Control bar share, the active artboard's X and Y (of that point) and W and H with the Constrain Width and Height Proportions link, its preset and orientation, and Move and Scale Artwork with Artboard. The Artboards section follows, with the name field, Artboard Options and Fill. The active artboard's name is a field. Typing a new name and pressing Enter or clicking elsewhere renames that artboard in one undo step, as the Artboards panel's rename does (`artboard.setProps {index, name}`); pressing Escape or leaving the field empty keeps the old name. A click on the Artboard Options icon beside the field opens Artboard Options for the active artboard, as double-clicking the Artboard tool's button does (`tool.options {tool: "artboard"}`). Pointer and key tests in `panels/properties.rs` cover both. Public references: [Resize artboards](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/add-edit-artboards/resize-artboards.html) and [Create and add new artboards](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/add-edit-artboards/add-new-artboards.html). -- **Artboard background colors:** each artboard can have a background color (`artboard.setProps {index, color}`, `color: null` removes it). With the Artboard tool, Properties has a Fill row: its list sets None, White or Black, and its chip and its Color Picker… item open the Color Picker for the artboard. Artboard Options has a Background Color row with a list that sets None, White or Black, and a color button. The canvas draws the artboard's paper in the color, multiplied with the paper color while Simulate Colored Paper is on, and the transparency grid still covers it. The native format saves the color, and a document without colors saves as before. Exports draw it behind each exported artboard's art, inside the artboard and in the color's own model: raster formats (on a transparent background too), PDF, SVG and EPS pages, `.ai` files' PDF pages, Export for Screens and print, whose preview shows it; files with editing data keep it as the artboard's color, not as art. Export for Screens has Include Artboard Fill beside Include Bleed (on by default and remembered; `includeArtboardFill: false`, which `document.export` and `file.print` take too, leaves it out) (#4937). Not done: `.ai` files the reference app reads keep it only in VectorCraft's editing data, and `.ai`/PDF import doesn't read a background color from the reference app's own data. Engine, canvas, Properties, Color Picker, Artboard Options, export (`fileio::tests_artboard_fill`) and Export for Screens dialog tests cover it. Public reference: [Apply colors to artboards](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/organize-manage-artboards/add-background-color-to-artboards.html). +- **Artboard background colors:** each artboard can have a background color (`artboard.setProps {index, color}`, `color: null` removes it). With the Artboard tool, Properties has a Fill row: its list sets None, White or Black, and its chip and its Color Picker… item open the Color Picker for the artboard. Artboard preview and confirmation require its opening document to be active. Artboard Options has a Background Color row with a list that sets None, White or Black, and a color button. The canvas draws the artboard's paper in the color, multiplied with the paper color while Simulate Colored Paper is on, and the transparency grid still covers it. The native format saves the color, and a document without colors saves as before. Exports draw it behind each exported artboard's art, inside the artboard and in the color's own model: raster formats (on a transparent background too), PDF, SVG and EPS pages, `.ai` files' PDF pages, Export for Screens and print, whose preview shows it; files with editing data keep it as the artboard's color, not as art. Export for Screens has Include Artboard Fill beside Include Bleed (on by default and remembered; `includeArtboardFill: false`, which `document.export` and `file.print` take too, leaves it out) (#4937). Not done: `.ai` files the reference app reads keep it only in VectorCraft's editing data, and `.ai`/PDF import doesn't read a background color from the reference app's own data. Engine, canvas, Properties, Color Picker, Artboard Options, export (`fileio::tests_artboard_fill`) and Export for Screens dialog tests cover it. Public reference: [Apply colors to artboards](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/organize-manage-artboards/add-background-color-to-artboards.html). - **Resizing several artboards:** with several artboards selected with the Artboard tool, a new W or H in Properties, the Transform panel or the Control bar, a preset or an orientation in Properties or the Control bar, and a new Width or Height in Artboard Options resize every selected artboard in one undo step (`artboard.setProps {artboards}`), and a Fill chosen in Properties colors each of them (#5698); a Shift- or Ctrl/Cmd-click on an Artboards panel row with another tool in use switches to the Artboard tool and selects as it does; with Scale Artwork with Artboard on, Properties, the Transform panel and the Control bar scale each object once, with the artboard it was inside before the change. The Transform panel, the Control bar and Artboard Options resize each one about its own reference point, a preset sizes each one in its own orientation, and X and Y still move the active artboard alone. Pointer and key tests in `panels/properties.rs`, dialog tests in `dialogs/tests.rs` and an engine test in `tests/xform.rs` cover them. Public references: [Artboard Enhancements In Illustrator CC](https://blog.adobe.com/en/publish/2017/11/10/artboard-enhancements-in-illustrator-cc) (a height and a width entered once resize every selected artboard) and [Using multiple artboards](https://helpx.adobe.com/illustrator/using/using-multiple-artboards.html) (2019). - **Artboard Escape routing:** Escape leaves Artboard editing for Selection; during a drag it first cancels the gesture. Headless egui key events cover idle Escape, active-drag cancellation and a subsequent Escape in `tests/distortkeys.rs`. - **Escape in the distort tools:** Escape during a Puppet Warp pin drag or turn, a Perspective Grid tool handle or plane widget drag, a Perspective Selection move, resize or plane widget drag, or a Liquify stroke cancels it: the art goes back to how the press found it, no undo step is added, and the tool stays chosen. Puppet Warp also selects again the pins selected before the press, and Escape during a Liquify Alt-drag puts the brush size back. Regression tests: `escape_cancels_*` in `crates/tools/src/distort/puppet.rs`, `perspective.rs` and `liquify.rs`, and `escape_cancels_a_puppet_warp_perspective_or_liquify_drag` in `tests/distortkeys.rs`.