Define Brush/Pattern: grey them while hidden colour channels leave the mask as the picture (#18232)

The desktop treats a masked layer's mask as the target in Composite when
every colour channel is hidden and no alpha channel is shown; the engine
helper now does too, and ignores a shown filter mask as the desktop does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dholzricandClaude Opus 5.5 committed 2026-12-01 17:06:14 -06:00
1 parent 93a9ffa3c9
commit 2d338e8b04
2 files changed
+37 -3

No files matched your search

+13 -3
View File
@@ -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,
}
}
@@ -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() {