From e20c330bd3c0a37fe1b24f9d777789b7c527c232 Mon Sep 17 00:00:00 2001 From: Taha-Mahmoodi <85902429+Taha-Mahmoodi@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:55:05 +0430 Subject: [PATCH] Gradients: paint.setStroke refuses a dithered gradient when "swatch" is null Review follow-up (CodeRabbit): the refusal skipped any request carrying a `swatch` key, so `"swatch": null` with a dithered gradient got through. Only a named swatch (a gradient swatch keeps its own dither) is exempt now. The dither test sends `"swatch": null`; it fails without the change. --- crates/engine/src/cmd/paint.rs | 5 +++-- crates/engine/src/tests_gradient.rs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 9b09392bd..6bdf1af96 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -403,8 +403,9 @@ fn set_paint(s: &mut Session, p: &Value, fill: bool) -> Result { } check_keep_model(p, cmd)?; let paint = paint_from(s, p)?.ok_or_else(|| bad(cmd, "give color, none, swatch or gradient"))?; - // As `paint.editGradient`: a `dither` given applies to gradient fills only. - if !fill && matches!(&paint, Paint::Gradient(g) if g.gradient.dither) && p.get("swatch").is_none() { + // As `paint.editGradient`: a `dither` given applies to gradient fills only. A gradient swatch + // (named) keeps its own dither; `"swatch": null` names none. + if !fill && matches!(&paint, Paint::Gradient(g) if g.gradient.dither) && p.get("swatch").and_then(Value::as_str).is_none() { return Err(bad(cmd, "`dither` applies to gradient fills (paint.setFill)")); } apply_paint(s, p, paint, fill) diff --git a/crates/engine/src/tests_gradient.rs b/crates/engine/src/tests_gradient.rs index 13a7aa4e2..8295a9835 100644 --- a/crates/engine/src/tests_gradient.rs +++ b/crates/engine/src/tests_gradient.rs @@ -441,6 +441,7 @@ fn dither_is_a_fill_gradient_option_that_saves_and_loads() { let before = node(&s, id).appearance.clone(); assert!(s.execute("paint.editGradient", &json!({"dither": true, "stroke": true})).is_err()); assert!(s.execute("paint.setStroke", &json!({"gradient": {"dither": true}})).is_err()); + assert!(s.execute("paint.setStroke", &json!({"swatch": null, "gradient": {"dither": true}})).is_err(), "a null swatch names none"); assert!(s.execute("paint.editGradient", &json!({"dither": "yes"})).is_err()); assert!(s.execute("paint.setFill", &json!({"gradient": {"dither": 1}})).is_err()); assert_eq!(node(&s, id).appearance, before);