PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Fade the target the command ran on, not the Channels panel's
Hector Villarreal5470e2fa0aa5
diff --git a/crates/engine/src/edit_menu_cmds.rs b/crates/engine/src/edit_menu_cmds.rsindex 4cb4b2e60..b12c9aafb 100644--- a/crates/engine/src/edit_menu_cmds.rs+++ b/crates/engine/src/edit_menu_cmds.rs@@ -13,7 +13,7 @@ use photocraft_raster::{Surface, from_rgba_into, to_rgba};use serde::{Deserialize, Serialize};use serde_json::{Value, json};-use crate::channel_cmds::ChannelTarget;+use crate::channel_cmds::Target;use crate::commands::{CommandSpec, blend_from_str, int, layer_param};use crate::{EngineError, Result, Session};@@ -68,16 +68,18 @@ fn fadeable(id: &str) -> bool {}/// Called after every successful command: remember a fadeable result.-pub(crate) fn after_command(s: &mut Session, id: &str) {+pub(crate) fn after_command(s: &mut Session, id: &str, params: &Value) {if !fadeable(id) {return;}let Some(st) = s.active() else { return };let label = st.history.undo_label().unwrap_or(id).to_string();- // A targeted alpha channel, or the Quick Mask, takes the edit instead of the layer (#7382).- let channel = match st.channel_view.target {- ChannelTarget::Alpha(i) if i < st.doc.channels.len() => Some(FadeTarget::Channel(i)),- ChannelTarget::Composite if st.doc.quick_mask.is_some() => Some(FadeTarget::QuickMask),+ // An alpha channel or the Quick Mask took the edit instead of the layer when the command ran+ // on it (#7382): its explicit `target`, or the one the Channels panel gave it.+ let run = crate::channel_cmds::inject_target(s, id, params.clone());+ let channel = match crate::channel_cmds::target_of(&run) {+ Target::Alpha(i) if i < st.doc.channels.len() => Some(FadeTarget::Channel(i)),+ Target::QuickMask if st.doc.quick_mask.is_some() => Some(FadeTarget::QuickMask),_ => None,};if let Some(target) = channel {diff --git a/crates/engine/src/edit_menu_cmds/tests.rs b/crates/engine/src/edit_menu_cmds/tests.rsindex 34b42a3a4..9298139d6 100644--- a/crates/engine/src/edit_menu_cmds/tests.rs+++ b/crates/engine/src/edit_menu_cmds/tests.rs@@ -128,6 +128,21 @@ fn fade_an_alpha_channel_or_the_quick_mask_at_all_depths() {}}+/// A command told to edit the layer (`"target": "pixels"`) does so with an alpha channel targeted,+/// and Fade then fades the layer, not the channel.+#[test]+fn fade_follows_the_target_the_command_ran_on() {+ let mut s = session(8);+ s.execute("channel.new", json!({"fill": "black"})).unwrap();+ s.execute("channel.target", json!({"channel": 0})).unwrap();+ s.execute("edit.fill", json!({"color": "#000000", "target": "pixels"})).unwrap();+ assert_eq!(px(&s, 5, 5)[0], 0.0, "the layer was filled");+ assert!(matches!(s.edit_state.fade.as_ref().map(|f| f.target), Some(FadeTarget::Pixels(_))));+ s.execute("edit.fade", json!({"opacity": 25})).unwrap();+ assert!((px(&s, 5, 5)[0] - 0.75).abs() < 0.01, "the layer faded");+ assert_eq!(s.active().unwrap().doc.channels[0].surface.pixel(5, 5)[0], 0.0, "the channel is left alone");+}+#[test]fn purge_commands() {let mut s = session(8);diff --git a/crates/engine/src/jobs.rs b/crates/engine/src/jobs.rsindex b30e56da3..b3237e766 100644--- a/crates/engine/src/jobs.rs+++ b/crates/engine/src/jobs.rs@@ -789,7 +789,7 @@ impl Session {if let Some(st) = self.active_mut() {crate::mask_view_cmds::fix(st);}- crate::edit_menu_cmds::after_command(self, id);+ crate::edit_menu_cmds::after_command(self, id, ¶ms);crate::automate_cmds::after_command(self, id);self.sync_preset_store();if !journal {