From 4b9d56154068f203b5474bb814571deb29b12972 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 13:37:24 -0800 Subject: [PATCH] Graphs: paint edits of a design's art alone leave the new-art paint as it is With only the art of a graph design in a series given or selected, paint.editGradient still set the default fill or stroke and the remembered paint, paint.swap swapped the default fill and stroke, paint.default reset them, and paint.invert and paint.complement with an item remembered the art's color. Each now returns without changing anything. An empty selection still edits the defaults as before. --- crates/engine/src/cmd/gradient.rs | 4 +++ crates/engine/src/cmd/graph/tests.rs | 37 ++++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 20 +++++++++++++-- docs/mcp.md | 4 ++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index 291aa1b59f..c6534c6367 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -579,6 +579,10 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { }; let new_default = apply_gradient_edit_in_model(&default_paint, &with_stored_stops(&for_default, &default_paint, &stored), None, &|_| true, model) .map_err(|e| bad(C, e))?; + // Only design art was given or selected: nothing changes, the defaults and the remembered paint included. + if selected && ids.is_empty() { + return Ok(json!({"ids": []})); + } let freeform = str_param(p, "kind").and_then(GradientKind::parse) == Some(GradientKind::Freeform); edit_items(s, &ids, item, C, "Gradient", !stroke, |n, index| { if index.is_none() diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index f8cf0af4ab..6a2e3cd3ad 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -507,6 +507,43 @@ fn stroke_edits_of_selected_design_art_leave_the_new_art_stroke() { assert_eq!(s.new_art_stroke().gradient_mode, mode, "paint.editGradient"); } +/// With only the art of a graph design given or selected, the gradient, swap, default and recolor commands leave the +/// paint for new art and the remembered colors as they are. +#[test] +fn paint_edits_of_design_art_alone_leave_the_defaults() { + let (mut s, _, _, art, _) = design_art(); + let fill = top_row(&s, art, true); + s.execute("select.set", &json!({"ids": []})).unwrap(); + s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap(); + s.execute("stroke.set", &json!({"weight": 3})).unwrap(); + let defaults = |s: &Session| format!("{:?}", (&s.paint, s.last_solid, &s.last_gradient, &s.recent_colors)); + let commands = [ + ("paint.editGradient", json!({"kind": "linear"})), + ("paint.editGradient", json!({"kind": "radial", "stroke": true})), + ("paint.swap", json!({})), + ("paint.default", json!({})), + ("paint.invert", json!({"item": fill, "stroke": false})), + ("paint.complement", json!({"item": fill, "stroke": false})), + ]; + for (cmd, p) in &commands { + let was = defaults(&s); + let mut q = p.clone(); + q["ids"] = json!([art.0]); + s.execute(cmd, &q).unwrap(); + assert_eq!(defaults(&s), was, "{cmd}, given"); + // Selecting the art makes the defaults take its paint. + s.execute("select.set", &json!({"ids": [art.0]})).unwrap(); + let was = defaults(&s); + s.execute(cmd, p).unwrap(); + assert_eq!(defaults(&s), was, "{cmd}, selected"); + s.execute("select.set", &json!({"ids": []})).unwrap(); + } + // With nothing selected, the swap still swaps the defaults. + let was = defaults(&s); + s.execute("paint.swap", &json!({})).unwrap(); + assert_ne!(defaults(&s), was); +} + /// `transparency.set` without `item` refuses the art of a graph design in a series, and given it with other objects /// sets only theirs. #[test] diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index a37c407041..73c92ac113 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -966,7 +966,13 @@ pub(super) fn restore_unpainted_stroke(ap: &mut Appearance, index: Option } fn swap(s: &mut Session, p: &Value) -> Result { - let ids = super::appearance::drop_design_art(&s.doc()?.doc, paint_targets(s, p)?); + let targets = paint_targets(s, p)?; + let given = !targets.is_empty(); + let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets); + // Only design art was given or selected: nothing changes, the defaults included. + if given && ids.is_empty() { + return ok(); + } if !ids.is_empty() { // When every object comes out as it was, the document and its undo history stay as they are. let before = s.doc()?.doc.clone(); @@ -1001,7 +1007,13 @@ fn swap(s: &mut Session, p: &Value) -> Result { } fn default_paint(s: &mut Session, p: &Value) -> Result { - let ids = super::appearance::drop_design_art(&s.doc()?.doc, paint_targets(s, p)?); + let targets = paint_targets(s, p)?; + let given = !targets.is_empty(); + let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets); + // Only design art was given or selected: nothing changes, the defaults included. + if given && ids.is_empty() { + return ok(); + } if !ids.is_empty() { // When every object comes out as it was, the document and its undo history stay as they are. let before = s.doc()?.doc.clone(); @@ -1073,6 +1085,10 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( let (r, shown_item) = match item { ItemTarget::Item { index, .. } => { let ids = super::appearance::drop_design_art(&s.doc()?.doc, item.targets(s, p)?); + // Only design art was given or selected: nothing changes, the remembered colors included. + if ids.is_empty() { + return Ok(json!({ "changed": 0 })); + } let mut changed = 0; edit_items(s, &ids, item, cmd, label, !stroke, |n, i| { let paint = diff --git a/docs/mcp.md b/docs/mcp.md index 3ec471eb84..a60a9dea96 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -832,7 +832,9 @@ design art is selected or given), `threeD.mapGraphic`, `appearance.transfer` with design art as its `target`, or as its `source` without `copy`, is an error. `paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert` and `paint.complement` with an `item`, `stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`, -`paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When the first selected object is design art, the commands +`paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When all their objects are design art, +`paint.editGradient`, `paint.swap`, `paint.default`, and `paint.invert` and `paint.complement` with an `item` also leave +the paint for new art and the remembered colors as they are. When the first selected object is design art, the commands do not use the Appearance panel's active row. To change the art, edit the design with `graph.design`. The graph also stores a paint or stroke weight that one of these commands changes on the topmost visible fill or stroke