Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Channels: clicking RGB hides the alpha channel overlay (fixes #4538) (#4564)

Marco Arnulfoadaebc084d65
diff --git a/crates/engine/src/channel_cmds.rs b/crates/engine/src/channel_cmds.rs
index 86bf55d1a..45391cac3 100644
--- a/crates/engine/src/channel_cmds.rs
+++ b/crates/engine/src/channel_cmds.rs
@@ -1226,7 +1226,12 @@ fn target(s: &mut Session, t: ChannelTarget) {
let v = &mut st.channel_view;
v.target = t;
match t {
- ChannelTarget::Composite | ChannelTarget::LayerMask | ChannelTarget::VectorMask => v.color_hidden.clear(),
+ // Like clicking RGB in Photoshop: the alpha overlays go away with their eyes.
+ ChannelTarget::Composite => {
+ v.color_hidden.clear();
+ v.alpha_visible.clear();
+ }
+ ChannelTarget::LayerMask | ChannelTarget::VectorMask => v.color_hidden.clear(),
ChannelTarget::Color(k) => {
v.color_hidden = (0..colors).map(|c| c != k).collect();
v.alpha_visible.clear();
diff --git a/crates/engine/src/channel_cmds/tests.rs b/crates/engine/src/channel_cmds/tests.rs
index 499b16c32..1d721ee5c 100644
--- a/crates/engine/src/channel_cmds/tests.rs
+++ b/crates/engine/src/channel_cmds/tests.rs
@@ -218,6 +218,20 @@ fn deleting_a_channel_remaps_all_surviving_eyes_and_targets() {
}
}
+#[test]
+fn targeting_the_composite_hides_the_alpha_overlay() {
+ for (cmd, params) in [("channel.target", json!({"channel": "composite"})), ("channel.target.composite", json!({}))] {
+ let mut s = session();
+ s.execute("channel.new", json!({})).unwrap();
+ assert!(s.active().unwrap().channel_view.alpha_shown(0));
+ s.execute(cmd, params).unwrap();
+ let st = s.active().unwrap();
+ assert_eq!(st.channel_view.visible_colors(3), 3, "{cmd}");
+ assert!(!st.channel_view.alpha_shown(0), "{cmd}: the alpha eye turns off");
+ assert!(st.channel_view.is_plain(&st.doc), "{cmd}: no overlay left on the image (#4538)");
+ }
+}
+
#[test]
fn every_colour_channel_can_hide_while_alpha_stays() {
let mut s = session();