From 7cf9fa9c476aabcf1642f39aeecd6edded57c8bd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 02:35:40 -0800 Subject: [PATCH] Gradient: reversed stops unlink the gradient swatch A stops write with reverse compares the final, reversed stops with the paint's current stops, so writing the same stops reversed clears the gradient swatch link while an unchanged write still keeps it. --- crates/engine/src/cmd/gradient.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index 22c99d9d8e..90222aae4b 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -527,16 +527,20 @@ fn apply_gradient_edit_in_model( switched = true; } } - let recolor = p.get("stops").is_some() || bool_or(p, "reverse", false); + let reverse = bool_or(p, "reverse", false); + let recolor = p.get("stops").is_some() || reverse; if let Some(stops) = p.get("stops") { let stops = parse_stops(stops)?; - // A paint whose stops stay as they are keeps its gradient swatch. - if stops != gp.gradient.stops { - gp.gradient.stops = stops; + let before = std::mem::replace(&mut gp.gradient.stops, stops); + if reverse { + // Midpoints mirrored with their segments. + gp.gradient.reverse(); + } + // A paint whose final stops stay as they are keeps its gradient swatch. + if gp.gradient.stops != before { gp.swatch = None; } - } - if bool_or(p, "reverse", false) { + } else if reverse { // Midpoints mirrored with their segments. gp.gradient.reverse(); } @@ -933,4 +937,11 @@ mod tests { let other = json!({"stops": [{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#000000"}]}); assert_eq!(swatch(&apply_gradient_edit(&paint, &other, None).unwrap()), None, "new stops unlink the swatch"); } + + #[test] + fn writing_the_same_stops_reversed_unlinks_the_gradient_swatch() { + let paint = linked(&[(0.0, "#ffffff"), (1.0, "#000000")]); + let reversed = json!({"stops": [{"offset": 0, "color": "#ffffff"}, {"offset": 1, "color": "#000000"}], "reverse": true}); + assert_eq!(swatch(&apply_gradient_edit(&paint, &reversed, None).unwrap()), None, "reversed stops unlink the swatch"); + } }