PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Take Fade's channel target only from commands routed to channels
Hector Villarreala8e64ee938cd
diff --git a/crates/engine/src/channel_cmds.rs b/crates/engine/src/channel_cmds.rsindex 991f40dc0..c061ce59c 100644--- a/crates/engine/src/channel_cmds.rs+++ b/crates/engine/src/channel_cmds.rs@@ -701,7 +701,7 @@ pub fn follows_target(id: &str) -> bool {}/// Commands whose target follows the Channels panel.-fn routed(id: &str) -> bool {+pub(crate) fn routed(id: &str) -> bool {id.starts_with("filter.")|| id == "plugin.run"|| id.starts_with("image.adjustments.")diff --git a/crates/engine/src/edit_menu_cmds.rs b/crates/engine/src/edit_menu_cmds.rsindex b12c9aafb..1a8440538 100644--- a/crates/engine/src/edit_menu_cmds.rs+++ b/crates/engine/src/edit_menu_cmds.rs@@ -75,9 +75,11 @@ pub(crate) fn after_command(s: &mut Session, id: &str, params: &Value) {let Some(st) = s.active() else { return };let label = st.history.undo_label().unwrap_or(id).to_string();// 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.+ // on it (#7382): its explicit `target`, or the one the Channels panel gave it. Only commands+ // routed to channels edit them; the others edit the layer whatever `target` says.let run = crate::channel_cmds::inject_target(s, id, params.clone());let channel = match crate::channel_cmds::target_of(&run) {+ _ if !crate::channel_cmds::routed(id) => None,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,diff --git a/crates/engine/src/edit_menu_cmds/tests.rs b/crates/engine/src/edit_menu_cmds/tests.rsindex 9298139d6..439fbba72 100644--- a/crates/engine/src/edit_menu_cmds/tests.rs+++ b/crates/engine/src/edit_menu_cmds/tests.rs@@ -143,6 +143,15 @@ fn fade_follows_the_target_the_command_ran_on() {assert_eq!(s.active().unwrap().doc.channels[0].surface.pixel(5, 5)[0], 0.0, "the channel is left alone");}+/// A command that only edits layers (Auto Tone) fades the layer, even given a channel `target`.+#[test]+fn fade_ignores_a_target_the_command_doesnt_take() {+ let mut s = session(8);+ s.execute("select.editInQuickMaskMode", json!({"on": true})).unwrap();+ s.execute("image.autoTone", json!({"target": "quickMask"})).unwrap();+ assert!(matches!(s.edit_state.fade.as_ref().map(|f| f.target), Some(FadeTarget::Pixels(_))));+}+#[test]fn purge_commands() {let mut s = session(8);