From 8ebb04999d25790f71f9bd88f7a268a6a2754aec Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 24 Oct 2026 11:54:24 -0600 Subject: [PATCH] Gradient Fill layer: default to Foreground to Transparent (#8708) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Layer › New Fill Layer › Gradient… without colours made an opaque foreground-to-background gradient, so a new gradient fill hid everything below it behind the background colour. Photoshop's Gradient Fill starts from Foreground to Transparent: the foreground at both ends, its opacity going from 100% to 0%. With no `to` colour the command now builds that (colour stops plus transparency stops); an explicit `to` still makes a two-colour gradient. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/commands.rs | 12 +++++++++--- crates/engine/src/gradient_fill_cmds/tests.rs | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs index 767a9791b0..6794501d84 100644 --- a/crates/engine/src/commands.rs +++ b/crates/engine/src/commands.rs @@ -1077,17 +1077,20 @@ fn build() -> Vec { "Gradient…", ["Layer", "New Fill Layer"], None, - r##"{"from":"#rrggbb","to":"#rrggbb","angle":deg=90,"style":"linear|radial|angle|reflected|diamond","reverse":bool,"path":"work"|saved path name|{…path}? (the active path: becomes the vector mask; else the selection is the layer mask)}"##, + r##"{"from":"#rrggbb"=foreground,"to":"#rrggbb"? (none: Foreground to Transparent),"angle":deg=90,"style":"linear|radial|angle|reflected|diamond","reverse":bool,"path":"work"|saved path name|{…path}? (the active path: becomes the vector mask; else the selection is the layer mask)}"##, has_doc, |s, p| { let a = color_param("layer.newFillLayer.gradient", p, "from", s.tools.foreground)?; - let b = color_param("layer.newFillLayer.gradient", p, "to", s.tools.background)?; + // Without a `to`, Photoshop's default Foreground to Transparent (#8708): the + // `from` colour at both ends, fading out through the transparency stops. + let to_transparent = p.get("to").is_none_or(Value::is_null); + let b = if to_transparent { a } else { color_param("layer.newFillLayer.gradient", p, "to", s.tools.background)? }; let angle = crate::gradient_fill_cmds::angle_param("layer.newFillLayer.gradient", p, 90.0)?; let style = crate::layer_style::gradient_style(p.get("style").and_then(Value::as_str).unwrap_or("linear")); let reverse = p.get("reverse").and_then(Value::as_bool).unwrap_or(false); let default_mask = layer_panel_option(s, "useDefaultMasksOnFillLayers", true); let id = s.edit("New Gradient Fill Layer", |doc, active| { - let fill = Fill::gradient( + let mut fill = Fill::gradient( vec![(0.0, Color::rgba(a[0], a[1], a[2], a[3])), (1.0, Color::rgba(b[0], b[1], b[2], b[3]))], angle, 1.0, @@ -1095,6 +1098,9 @@ fn build() -> Vec { reverse, ) .in_mode(doc.mode); + if to_transparent && let Fill::Gradient { opacity_stops, .. } = &mut fill { + *opacity_stops = vec![(0.0, 1.0), (1.0, 0.0)]; + } let mut l = Layer::new(doc.next_layer_name("Gradient Fill"), LayerContent::Fill(fill)); mask_new_layer(doc, &mut l, p, "layer.newFillLayer.gradient", default_mask)?; let id = doc.insert_above(*active, l); diff --git a/crates/engine/src/gradient_fill_cmds/tests.rs b/crates/engine/src/gradient_fill_cmds/tests.rs index 3c0c2f3c6a..eca8a7bc12 100644 --- a/crates/engine/src/gradient_fill_cmds/tests.rs +++ b/crates/engine/src/gradient_fill_cmds/tests.rs @@ -386,3 +386,22 @@ fn stop_rejects_huge_indices_without_panicking() { assert_eq!(midpoints, vec![0.25]); assert_eq!(s.active().unwrap().history.past_len(), h + 1); } + +#[test] +fn new_gradient_fill_layer_defaults_to_foreground_to_transparent() { + // #8708: Photoshop's Layer › New Fill Layer › Gradient… starts from Foreground to + // Transparent: the foreground at both ends, its opacity 100% to 0%. A `to` colour keeps a + // two-colour gradient. + let mut s = session(8, "transparent"); + s.tools.foreground = [0.2, 0.4, 0.6, 1.0]; + s.tools.background = [1.0, 1.0, 1.0, 1.0]; + s.execute("layer.newFillLayer.gradient", json!({})).unwrap(); + let Fill::Gradient { stops, opacity_stops, .. } = active_fill(&s) else { panic!("not a gradient") }; + let fg = Color::rgba(0.2, 0.4, 0.6, 1.0); + assert_eq!(stops, vec![(0.0, fg), (1.0, fg)]); + assert_eq!(opacity_stops, vec![(0.0, 1.0), (1.0, 0.0)]); + s.execute("layer.newFillLayer.gradient", json!({"to": "#ff0000"})).unwrap(); + let Fill::Gradient { stops, opacity_stops, .. } = active_fill(&s) else { panic!("not a gradient") }; + assert_eq!(stops[1].1, Color::rgba(1.0, 0.0, 0.0, 1.0)); + assert!(opacity_stops.is_empty()); +}