From d00e25c9622b5adb540c962df28415c761a5c1eb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 17:37:47 -0800 Subject: [PATCH] Paste on All Artboards: swatch conflicts leave copied artboard backgrounds out Paste on All Artboards leaves copied artboards behind, so it does not convert their background colors: edit.paste passes the boards only in the other paste modes, and clipboard.profileMismatch takes allArtboards for the same reason. clipboard.conflicts always counted the backgrounds. When only a copied artboard's background had another profile, it treated the paste as converting and listed the swatches the document had edited since the copy, so Swatch Conflict asked about swatches while the paste itself converted nothing. - clipboard.conflicts takes allArtboards (true or false, default false; other values are refused). With true it lists the conflicts as Paste on All Artboards brings the colors, without the copied artboards' backgrounds. - The Swatch Conflict dialog passes allArtboards: true when the paste it asks about is edit.pasteOnAllArtboards. - Params text and docs/mcp.md describe the parameter. --- crates/engine/src/cmd/clipboard.rs | 9 ++++-- crates/engine/tests/color_settings.rs | 31 +++++++++++++++++++ .../src/dialogs/profile_mismatch/tests.rs | 25 +++++++++++++++ crates/ui-egui/src/dialogs/swatch_conflict.rs | 14 ++++++--- docs/mcp.md | 3 +- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/cmd/clipboard.rs b/crates/engine/src/cmd/clipboard.rs index c6c1da2980..610498f56a 100644 --- a/crates/engine/src/cmd/clipboard.rs +++ b/crates/engine/src/cmd/clipboard.rs @@ -47,7 +47,7 @@ pub fn specs() -> Vec { "Swatch Conflicts", [], None, - "{profileMismatch?: as edit.paste} → {swatches: [{name, document, clipboard, spot}]} the global or spot swatches the copied objects use whose name the active document gives another colour (`document`/`clipboard`: #rrggbb, the pasted colour as the paste brings it, converted when profileMismatch or the policy converts it): Paste asks Merge or Add for each (pass the answer as edit.paste* {swatchConflict}). Pasting back into the document the objects came from raises none, unless the paste converts its colours", + "{profileMismatch?: as edit.paste, allArtboards?: false (true: for edit.pasteOnAllArtboards, which leaves the background colors of copied artboards behind)} → {swatches: [{name, document, clipboard, spot}]} the global or spot swatches the copied objects use whose name the active document gives another colour (`document`/`clipboard`: #rrggbb, the pasted colour as the paste brings it, converted when profileMismatch or the policy converts it): Paste asks Merge or Add for each (pass the answer as edit.paste* {swatchConflict}). Pasting back into the document the objects came from raises none, unless the paste converts its colours", has_doc, conflicts ), @@ -568,9 +568,12 @@ fn import_svg(s: &mut Session, p: &Value) -> Result { fn conflicts(s: &mut Session, p: &Value) -> Result { let hex = |w: &Swatch| w.paint.color().map(|c| c.to_hex()); // The swatches as the paste brings them: converted from another profile when it converts. - let profile = super::colormgmt::PasteProfile::param(p, "clipboard.conflicts")?; + const CMD: &str = "clipboard.conflicts"; + let profile = super::colormgmt::PasteProfile::param(p, CMD)?; + // Paste on All Artboards leaves the copied artboards, and so their backgrounds, behind. + let all_artboards = super::switch_or(p, "allArtboards", false, CMD)?; let st = s.doc()?; - let (converted, _) = super::colormgmt::paste_profiles(&s.clipboard, &st.doc, profile, true); + let (converted, _) = super::colormgmt::paste_profiles(&s.clipboard, &st.doc, profile, !all_artboards); let list: Vec = converted .as_ref() .unwrap_or(&s.clipboard) diff --git a/crates/engine/tests/color_settings.rs b/crates/engine/tests/color_settings.rs index c07d741265..4888c3ae25 100644 --- a/crates/engine/tests/color_settings.rs +++ b/crates/engine/tests/color_settings.rs @@ -1767,6 +1767,37 @@ fn paste_on_all_artboards_leaves_artboard_backgrounds_out() { assert!(r.get("profileMismatch").is_none(), "{r}"); } +/// The swatch conflicts Paste on All Artboards raises leave copied artboard backgrounds out, as the +/// paste does: pasting back into the document the objects came from, where only the RGB background +/// of the copied artboard now has another profile, converts nothing for it, so its edited CMYK +/// swatch raises no conflict. A plain paste, which brings the background and converts it, compares +/// the swatches and lists the edited one. +#[test] +fn swatch_conflicts_on_all_artboards_leave_artboard_backgrounds_out() { + let _g = settings(); + let _reset = ColorSettingsReset { profile: None, paths: vec![] }; + let mut s = session(); + exec(&mut s, "swatch.new", json!({"name": "Brand", "color": {"c": 20, "m": 40, "y": 60, "k": 10}, "global": true})); + let ink = rect(&mut s, 0.0, 0.0, 10.0, 10.0); + exec(&mut s, "paint.setFill", json!({"ids": [ink.0], "swatch": "Brand"})); + exec(&mut s, "paint.setStroke", json!({"ids": [ink.0], "none": true})); + exec(&mut s, "artboard.setProps", json!({"index": 0, "color": "#3366cc"})); + exec(&mut s, "edit.assignProfile", json!({"rgb": cms::WIDE_GAMUT_RGB})); + exec(&mut s, "artboard.copy", json!({"index": 0})); + exec(&mut s, "edit.assignProfile", json!({"rgb": null})); + exec(&mut s, "swatch.edit", json!({"name": "Brand", "color": {"c": 60, "m": 40, "y": 20, "k": 0}})); + let conflicts = |s: &mut Session, p: serde_json::Value| exec(s, "clipboard.conflicts", p)["swatches"].as_array().unwrap().len(); + assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert"})), 1, "a plain paste converts the RGB background"); + assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert", "allArtboards": true})), 0); + assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert", "allArtboards": false})), 1); + assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert", "allArtboards": null})), 1, "null is the default"); + for bad in [json!("yes"), json!(1)] { + assert!(s.execute("clipboard.conflicts", &json!({ "allArtboards": bad })).is_err(), "{bad}"); + } + let r = exec(&mut s, "edit.pasteOnAllArtboards", json!({"profileMismatch": "convert"})); + assert!(r.get("profileMismatch").is_none(), "{r}"); +} + /// A converting paste back into the document the objects came from (its profile changed since the /// copy) still takes its image blobs as the document's own: an image whose blob under its key /// changed since keeps that key, and so shows the document's blob. diff --git a/crates/ui-egui/src/dialogs/profile_mismatch/tests.rs b/crates/ui-egui/src/dialogs/profile_mismatch/tests.rs index 358c6f428e..19b8105cf4 100644 --- a/crates/ui-egui/src/dialogs/profile_mismatch/tests.rs +++ b/crates/ui-egui/src/dialogs/profile_mismatch/tests.rs @@ -385,6 +385,7 @@ fn opening_and_pasting_ask_about_profiles() { assert_eq!(count(&app), before + 1); swatch_conflicts_are_asked_again_when_they_change(&mut app); all_artboards_leaves_backgrounds_out(&mut app); + all_artboards_asks_no_swatch_conflict_for_backgrounds(&mut app); // It changes the working space: last. app.run("edit.colorSettings", json!({"askMismatchOpen": true})).unwrap(); an_answer_waits_for_the_question_it_answers(&mut app, &tagged); @@ -410,3 +411,27 @@ fn all_artboards_leaves_backgrounds_out(app: &mut VectorcraftApp) { assert_eq!(listed(app, "edit.paste"), Some(1), "the background is RGB"); assert_eq!(listed(app, ALL_ARTBOARDS), Some(0)); } + +/// Swatch Conflict for Paste on All Artboards asks about the colors it brings, without the +/// backgrounds of copied artboards: pasting back into the document the art came from, where only +/// the RGB background now has another profile, converts nothing, so the edited CMYK swatch is no +/// conflict and the paste runs. A plain paste converts the background and asks. +fn all_artboards_asks_no_swatch_conflict_for_backgrounds(app: &mut VectorcraftApp) { + use super::super::swatch_conflict; + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + app.run("swatch.new", json!({"name": "Brand", "color": {"c": 20, "m": 40, "y": 60, "k": 10}, "global": true})).unwrap(); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + app.run("paint.setFill", json!({"swatch": "Brand"})).unwrap(); + app.run("paint.setStroke", json!({"none": true})).unwrap(); + app.run("artboard.setProps", json!({"index": 0, "color": "#3366cc"})).unwrap(); + app.run("edit.assignProfile", json!({ "rgb": cms::WIDE_GAMUT_RGB })).unwrap(); + app.run("artboard.copy", json!({"index": 0})).unwrap(); + app.run("edit.assignProfile", json!({ "rgb": null })).unwrap(); + app.run("swatch.edit", json!({"name": "Brand", "color": {"c": 60, "m": 40, "y": 20, "k": 0}})).unwrap(); + let r = app.run("edit.paste", json!({"profileMismatch": "convert"})).unwrap(); + assert_eq!(r["dialog"], swatch_conflict::KIND, "{r}"); + super::super::cancel(app); + let r = app.run(ALL_ARTBOARDS, json!({"profileMismatch": "convert"})).unwrap(); + assert!(r.get("dialog").is_none() && r["ids"].as_array().is_some_and(|ids| !ids.is_empty()), "{r}"); + assert!(app.ui.dialog.is_none()); +} diff --git a/crates/ui-egui/src/dialogs/swatch_conflict.rs b/crates/ui-egui/src/dialogs/swatch_conflict.rs index 96ff733c42..b3dc56c372 100644 --- a/crates/ui-egui/src/dialogs/swatch_conflict.rs +++ b/crates/ui-egui/src/dialogs/swatch_conflict.rs @@ -36,7 +36,7 @@ pub fn ask(app: &mut VectorcraftApp, command: &str, params: &Value) -> Option DialogResult { // pasted swatches), it asks again about them instead. let asked = list.to_vec(); app.ui.dialog = None; - let changed = |app: &mut VectorcraftApp, _: &str, params: &Value| found(app, params).is_some_and(|now| now != asked); + let changed = |app: &mut VectorcraftApp, command: &str, params: &Value| found(app, command, params).is_some_and(|now| now != asked); let recheck = crate::placing::Recheck { key: "swatchConflict", changed: &changed }; let deferred = d.fields.get("__deferredPaste").and_then(Value::as_u64); crate::placing::confirm_swatch_paste(app, &d.str("__command"), params, deferred, Some(&recheck)) } -/// The swatch conflicts pasting with `params` raises (`clipboard.conflicts`), with the swatches as -/// the paste brings them: converted from another profile when it converts. -fn found(app: &mut VectorcraftApp, params: &Value) -> Option> { +/// The swatch conflicts paste `command` with `params` raises (`clipboard.conflicts`), with the +/// swatches as the paste brings them: converted from another profile when it converts, and for +/// Paste on All Artboards without the backgrounds of copied artboards, which it leaves behind. +fn found(app: &mut VectorcraftApp, command: &str, params: &Value) -> Option> { let mut q = json!({}); if let Some(m) = params.get("profileMismatch") { q["profileMismatch"] = m.clone(); } + if command == "edit.pasteOnAllArtboards" { + q["allArtboards"] = json!(true); + } let found = app.session.execute("clipboard.conflicts", &q).ok()?; found["swatches"].as_array().cloned() } diff --git a/docs/mcp.md b/docs/mcp.md index e7abf476a9..71dcaf7a11 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9105,7 +9105,8 @@ light one, by the wedge colors as pasted: a wedge linked to a swatch merged with color first. A global or spot swatch whose name the document gives another colour is a conflict: `clipboard.conflicts` lists -them, and `swatchConflict` answers: `"merge"` (the default: the objects take the document's swatch), `"add"` (the +them (with `allArtboards: true`, the colors as Paste on All Artboards brings them, without the background colors of +copied artboards), and `swatchConflict` answers: `"merge"` (the default: the objects take the document's swatch), `"add"` (the pasted swatch comes in renamed) or one answer per name. When a merged swatch turns a pie's wedge from light to dark or back, the legend labels in that pie's wedges take the contrast a redraw gives them (white on a dark wedge, black on a light one), unless the legend labels have a fill of their own. Pasting back into the document the objects came from