mirror of
https://github.com/storytold/photocraft.git
synced 2026-10-24 09:57:08 -06:00
Address CodeRabbit review: an opacity-only style preset added with ⇧ sets the opacity (#4049)
`style.presets.new` with `includeBlending: false` and an explicit `opacity` stores only that opacity, but `apply` with `add: true` skipped the blending block unless the preset had a blend mode, so the layer kept its opacity. Test: an_opacity_only_style_added_sets_just_the_opacity (also checks the layer's blend mode and Fill stay). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8c04b175ec
commit
f38004e721
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user