VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Recolor: art a row leaves unchanged loses its link to a rewritten group swatch
dotCooCoob8436385e8ad
diff --git a/crates/engine/src/cmd/recolor.rs b/crates/engine/src/cmd/recolor.rsindex 405436842..731d9ea55 100644--- a/crates/engine/src/cmd/recolor.rs+++ b/crates/engine/src/cmd/recolor.rs@@ -31,7 +31,7 @@ pub fn specs() -> Vec<CommandSpec> {"Recolor Artwork",["Edit", "Edit Colors"],None,- "{map: rows [{from: [colour keys (recolor.colors) or \"#rrggbb\" (every colour shown as that hex)], to: colour (hex, key, {c,m,y,k} or {l,a,b}) | null, exclude?: false (the row's colours are kept)}] | {\"key or #rrggbb\": colour, …} (one row per colour), method?: \"exact\" (default)|\"preserveTints\"|\"scaleTints\"|\"tintsShades\"|\"hueShift\" (how a row's colours take its new colour, relative to the row's darkest, average or most saturated colour), limitTo?: swatch library id or name; or \"document\" (the document's swatches): new colours snap to its nearest colour, group?: colour group to rewrite, groupColors?: [colour] (what `group` is rewritten with; default: the rows' new colours, in order, excluded rows left out), rename?: the group's new name, includeImages?: true, includePatterns?: true} recolour the selection (gradients, text, meshes, image pixels and pattern tiles included; each new colour keeps the model of the one it replaces (model?: \"keep\" default | \"new\" (the new colour's own model, so a CMYK colour replacing RGB art gives CMYK art) | \"document\" (the document's colour mode)), except a library swatch's with limitTo: art takes the swatch itself, linked to a global or spot colour at its tints, and the swatch joins the document's swatches; art linked to a global swatch of `group` that is rewritten with its row's new color stays linked to it, at its tint; other recolored art loses its swatch link) and the group, as one undo step → {changed, swatches: [names added to the document's swatches], relinked?: with group, the other paints linked to its global swatches that took their new colors, note?: set when a colour kept a model other than its new colour's (see model)}",+ "{map: rows [{from: [colour keys (recolor.colors) or \"#rrggbb\" (every colour shown as that hex)], to: colour (hex, key, {c,m,y,k} or {l,a,b}) | null, exclude?: false (the row's colours are kept)}] | {\"key or #rrggbb\": colour, …} (one row per colour), method?: \"exact\" (default)|\"preserveTints\"|\"scaleTints\"|\"tintsShades\"|\"hueShift\" (how a row's colours take its new colour, relative to the row's darkest, average or most saturated colour), limitTo?: swatch library id or name; or \"document\" (the document's swatches): new colours snap to its nearest colour, group?: colour group to rewrite, groupColors?: [colour] (what `group` is rewritten with; default: the rows' new colours, in order, excluded rows left out), rename?: the group's new name, includeImages?: true, includePatterns?: true} recolour the selection (gradients, text, meshes, image pixels and pattern tiles included; each new colour keeps the model of the one it replaces (model?: \"keep\" default | \"new\" (the new colour's own model, so a CMYK colour replacing RGB art gives CMYK art) | \"document\" (the document's colour mode)), except a library swatch's with limitTo: art takes the swatch itself, linked to a global or spot colour at its tints, and the swatch joins the document's swatches; art linked to a global swatch of `group` that is rewritten with its row's new color stays linked to it, at its tint; other recolored art, and art in a row linked to a global swatch of `group` that is rewritten with another color, keeps its row's new color and loses its swatch link) and the group, as one undo step → {changed, swatches: [names added to the document's swatches], relinked?: with group, the other paints linked to its global swatches that took their new colors, note?: set when a colour kept a model other than its new colour's (see model)}",has_doc,apply),@@ -354,7 +354,8 @@ impl ColorMap {/// swatch links its colours to it (at their tints; shades and other hues stay unlinked), a/// process swatch gives its colour in its own model; a color linked to a global swatch of the/// rewritten group that takes the row's new color keeps its link (at its tint in the row);- /// other rows map the colour, which loses its link when it changes. True when anything changed.+ /// other rows map the colour, which loses its link when it changes or when the group's rewrite+ /// would change it. True when anything changed.fn map_link(&self, c: &mut Color, link: &mut Option<String>, tint: &mut f32) -> bool {let Some(i) = self.row_of(*c) else { return false };let (Some(row), Some(l)) = (self.rows.get(i), self.links.get(i)) else { return false };@@ -385,7 +386,10 @@ impl ColorMap {row.map(*c)}};- if new == *c {+ // A color its row leaves as it is still loses its link to a swatch of the rewritten group+ // when the rewrite would give it another color.+ let rewritten = link.as_deref().and_then(|n| self.group.iter().find(|g| g.name == n)).is_some_and(|g| g.shown.tinted(*tint) != new);+ if new == *c && !rewritten {return false;}*c = new;diff --git a/crates/engine/src/tests_recolor.rs b/crates/engine/src/tests_recolor.rsindex bf9879e1b..49869369a 100644--- a/crates/engine/src/tests_recolor.rs+++ b/crates/engine/src/tests_recolor.rs@@ -430,6 +430,14 @@ fn apply_with_a_group_keeps_art_linked_to_its_global_swatches() {run(&mut s, "recolor.apply", json!({"map": {"#2878f0": "#ff6a00"}, "group": "Brand", "groupColors": ["#123456"]}));assert_eq!(link(&s, full), (orange, None, 1.0));assert_eq!(swatch_hex(&s), "#123456");+ // A row that leaves the art's color as it is while the swatch is rewritten with another color:+ // the art keeps its color, unlinked.+ run(&mut s, "edit.undo", json!({}));+ select_all(&mut s);+ let blue = Color::from_hex("#2878f0").unwrap();+ run(&mut s, "recolor.apply", json!({"map": {"#2878f0": "#2878f0"}, "group": "Brand", "groupColors": ["#123456"]}));+ assert_eq!(link(&s, full), (blue, None, 1.0));+ assert_eq!(swatch_hex(&s), "#123456");// Without a group the swatch is unchanged, so the art takes the new color unlinked.run(&mut s, "edit.undo", json!({}));select_all(&mut s);diff --git a/docs/mcp.md b/docs/mcp.mdindex b7ec3be58..c3131f906 100644--- a/docs/mcp.md+++ b/docs/mcp.md@@ -1694,7 +1694,9 @@ the others turn by the same hue). `limitTo` snaps new colours to a swatch librarstep (art linked to its global swatches follows), and `recolor.apply` with `group` recolours the art and rewrites thegroup together. Art linked to one of the group's global swatches stays linked when the swatch is rewritten with itsrow's new color (the default without `groupColors` when the rows follow the group's order), so a later `swatch.edit` still-reaches it; the reply's `relinked` counts the other linked paints that took the group's new colors. Without `group`,+reaches it; the reply's `relinked` counts the other linked paints that took the group's new colors. Art in a row that+is linked to a swatch rewritten with another color keeps its row's new color, even an unchanged one, and is no longer+linked to the swatch. Without `group`,the swatch keeps its color and the recolored art is no longer linked to it.```json