diff --git a/crates/engine-core/src/cmd/pattern_cmds.rs b/crates/engine-core/src/cmd/pattern_cmds.rs index 9f2246fbc2..4ba1488a97 100644 --- a/crates/engine-core/src/cmd/pattern_cmds.rs +++ b/crates/engine-core/src/cmd/pattern_cmds.rs @@ -456,14 +456,24 @@ fn for_each_band(p: &Pattern, w: u32, h: u32, mut f: impl FnMut(&[[f32; 4]])) { } } -/// A layer mask is the edit target: the active pixel layer's or group's mask is targeted, or the active layer is an -/// adjustment layer with a mask, which is what it edits. Define Pattern and Define Brush Preset are greyed then (#18232). +/// A layer mask is the edit target: the active pixel layer's or group's mask is targeted, the active layer is an +/// adjustment layer with a mask, which is what it edits, or every colour channel is hidden with no alpha channel shown, so +/// the mask is the picture (as the desktop's target rule reads it). A shown filter mask is not the layer mask. Define +/// Pattern and Define Brush Preset are greyed then (#18232). pub fn layer_mask_targeted(s: &Session) -> bool { let Some(st) = s.active() else { return false }; let Some(layer) = st.active_layer.and_then(|id| st.doc.layer(id)).filter(|l| l.mask.is_some()) else { return false }; + if crate::mask_view_cmds::current(st).is_some_and(|v| v.filter) { + return false; + } match st.channel_view.target { crate::channel_cmds::ChannelTarget::LayerMask => true, - crate::channel_cmds::ChannelTarget::Composite => st.doc.quick_mask.is_none() && matches!(layer.content, LayerContent::Adjustment(_)), + crate::channel_cmds::ChannelTarget::Composite if st.doc.quick_mask.is_none() => { + let view = &st.channel_view; + let colors_off = view.visible_colors(crate::channel_cmds::color_count(&st.doc)) == 0; + let alpha_on = (0..st.doc.channels.len()).any(|i| view.alpha_shown(i)); + matches!(layer.content, LayerContent::Adjustment(_)) || (colors_off && !alpha_on) + } _ => false, } } diff --git a/crates/engine-paint/src/cmd/brush_cmds/define_brush_mask_target_tests.rs b/crates/engine-paint/src/cmd/brush_cmds/define_brush_mask_target_tests.rs index 17c64ac9a2..76a76fdeca 100644 --- a/crates/engine-paint/src/cmd/brush_cmds/define_brush_mask_target_tests.rs +++ b/crates/engine-paint/src/cmd/brush_cmds/define_brush_mask_target_tests.rs @@ -95,6 +95,30 @@ fn targeting_the_composite_again_enables_them_with_the_same_tip() { s.execute("edit.definePattern", json!({"name": "Pattern"})).unwrap(); } +/// With every colour channel hidden and no alpha channel shown, the mask is the picture and the target; showing a colour +/// channel or an alpha channel again makes the items available. +#[test] +fn hiding_every_colour_channel_greys_them_on_a_masked_layer() { + let mut s = document(); + s.execute("layer.layerMask.revealAll", json!({})).unwrap(); + target(&mut s, json!("composite")); + s.execute("channel.setVisible", json!({"channel": "composite", "visible": false})).unwrap(); + assert_refused(&mut s, "every colour channel hidden"); + s.execute("channel.setVisible", json!({"channel": {"color": 0}, "visible": true})).unwrap(); + assert_enabled(&mut s, "one colour channel shown again"); + + s.execute("channel.new", json!({})).unwrap(); + target(&mut s, json!("composite")); + s.execute("channel.setVisible", json!({"channel": "composite", "visible": false})).unwrap(); + s.execute("channel.setVisible", json!({"channel": {"alpha": 0}, "visible": true})).unwrap(); + assert_enabled(&mut s, "an alpha channel shown"); + + // Without a mask there is nothing else to target. + let mut s = document(); + s.execute("channel.setVisible", json!({"channel": "composite", "visible": false})).unwrap(); + assert_enabled(&mut s, "no mask, every colour channel hidden"); +} + /// Not a layer mask target: these keep today's gates. #[test] fn other_targets_and_layer_kinds_stay_enabled() {