PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Address CodeRabbit review: an opacity-only style preset added with ⇧ sets the opacity (#4049)
David Mannf38004e72161
diff --git a/crates/engine/src/presets/styles.rs b/crates/engine/src/presets/styles.rsindex 04e4c831c..eb7cc17be 100644--- a/crates/engine/src/presets/styles.rs+++ b/crates/engine/src/presets/styles.rs@@ -212,7 +212,9 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {}l.effects.psd_raw = None;l.effects.enabled = true;- if !add || style.blend.is_some() {+ // Adding keeps the layer's blending unless the preset carries some: a blend mode, or+ // an Opacity saved on its own (`style.presets.new` with `includeBlending: false`).+ if !add || style.blend.is_some() || style.opacity.is_some() {if let Some(b) = style.blend {l.blend = b;}diff --git a/crates/engine/src/presets/tests.rs b/crates/engine/src/presets/tests.rsindex 1cbf3916b..b19611783 100644--- a/crates/engine/src/presets/tests.rs+++ b/crates/engine/src/presets/tests.rs@@ -477,6 +477,25 @@ fn styles_apply_to_selected_layers_and_new_from_layer() {assert!(px[(24 * 48 + 24) * 4 + 3] == 255);}+/// A preset saved without blending options but with an explicit Opacity carries only that+/// opacity: ⇧-click (`add`) sets it and leaves the layer's blend mode and Fill alone.+#[test]+fn an_opacity_only_style_added_sets_just_the_opacity() {+ let mut s = session(8);+ let a = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().map(LayerId).unwrap_or_else(|| active(&s));+ s.execute("style.presets.new", json!({"name": "Faded", "includeBlending": false, "effects": [["stroke", {"size": 2}]], "opacity": 40})).unwrap();+ s.edit("Blending fixture", |doc, _| {+ let l = doc.layer_mut(a).unwrap();+ (l.blend, l.fill_opacity, l.opacity) = (photocraft_doc::BlendMode::Multiply, 0.7, 0.9);+ Ok(())+ })+ .unwrap();+ s.execute("style.presets.apply", json!({"preset": "Faded", "add": true, "layer": a.0})).unwrap();+ let l = s.active().unwrap().doc.layer(a).unwrap().clone();+ assert_eq!((l.blend, l.fill_opacity, l.opacity), (photocraft_doc::BlendMode::Multiply, 0.7, 0.4));+ assert_eq!(l.effects.items.len(), 1);+}+#[test]fn styles_with_pattern_overlay_copy_the_pattern() {let mut s = session(8);