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);