Merge #18009 into the merge queue batch

Brush: alert when an adjustment layer's content is targeted instead of painting its mask
This commit is contained in:
David Mann committed 2026-11-30 00:25:24 +01:00
commit 87f5802e6c
2 files changed
+99

No files matched your search

@@ -0,0 +1,72 @@
//! #17640: with an adjustment layer's own content targeted (not its mask), a Brush click opens the
//! alert "Could not use the brush tool because the content of the layer is not directly editable."
//! with OK; the mask is unchanged and no History state is added. With the mask targeted the Brush
//! paints the mask as before.
use serde_json::json;
use super::brush_refusal_alert_tests::{alerts, app, refused, steps, stroke};
use super::*;
const CONTENT_ALERT: &str = "Could not use the brush tool because the content of the layer is not directly editable.";
/// The fixture's painted layer, then a Levels adjustment layer above it with its Reveal All mask.
fn levels(tool: Tool) -> Box<PhotocraftApp> {
let mut app = app(tool);
app.run("layer.newAdjustmentLayer.levels", json!({})).unwrap();
app.sync_views();
let st = app.session.active().unwrap();
let layer = st.doc.layer(st.active_layer.unwrap()).unwrap();
assert!(matches!(layer.content, photocraft_doc::LayerContent::Adjustment(_)) && layer.mask.is_some());
app
}
fn mask_level(app: &PhotocraftApp, x: i32, y: i32) -> f32 {
let st = app.session.active().unwrap();
st.doc.layer(st.active_layer.unwrap()).unwrap().mask.as_ref().unwrap().surface.pixel(x, y)[0]
}
#[test]
fn the_content_targeted_gets_the_alert_and_the_mask_stays() {
let mut app = levels(Tool::Brush);
app.run("channel.target.composite", json!({})).unwrap();
assert!(!app.ui.mask_target, "the content is targeted");
refused(&mut app, CONTENT_ALERT);
assert_eq!(mask_level(&app, 32, 32), 1.0, "the mask stays white");
}
#[test]
fn the_mask_targeted_is_painted_as_before() {
let mut app = levels(Tool::Brush);
assert!(app.ui.mask_target, "a new adjustment layer targets its mask");
// The mask's own colour pair (white on black until picked) is in use: paint black.
app.run("tools.setColors", json!({"foreground": "#000000"})).unwrap();
let before = steps(&app);
stroke(&mut app);
assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app));
assert_eq!(steps(&app), before + 1, "one Brush Tool state");
assert_eq!(mask_level(&app, 32, 32), 0.0, "the mask is painted black");
}
#[test]
fn targeting_the_mask_again_paints_it() {
let mut app = levels(Tool::Brush);
app.run("channel.target.composite", json!({})).unwrap();
app.run("channel.target.layerMask", json!({})).unwrap();
assert!(app.ui.mask_target);
let before = steps(&app);
stroke(&mut app);
assert!(alerts(&app).is_empty());
assert_eq!(steps(&app), before + 1);
}
#[test]
fn other_tools_keep_painting_the_mask() {
// Measured for the Brush only: the Pencil (#17563) and the others keep today's behaviour.
let mut app = levels(Tool::Pencil);
app.run("channel.target.composite", json!({})).unwrap();
let before = steps(&app);
stroke(&mut app);
assert!(alerts(&app).is_empty());
assert_eq!(steps(&app), before + 1);
}
+27
View File
@@ -16,6 +16,8 @@ pub const LOCKED: &str = "Could not use the {tool} because the layer is locked."
pub const GROUP: &str = "Could not use the {tool} because the pixels in a group cannot be edited without merging the group.";
/// The Clone Stamp's group alert, measured with Sample: Current Layer (#12608): the group is its source.
pub const CLONE_STAMP_GROUP: &str = "Could not use the {tool} because the source is a group.";
/// The Brush's alert when an adjustment layer's own content, not its mask, is targeted (#17640).
pub const CONTENT: &str = "Could not use the {tool} because the content of the layer is not directly editable.";
/// The Remove tool's one measured alert, Lock All (#12552): it doesn't name the tool.
pub const REMOVE_LOCKED: &str = "Can't use the tool because the layer is locked.";
@@ -114,6 +116,12 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
}
return (layer_refusal(app, tool)? == GROUP).then(|| crate::i18n::fmt(tl!(CLONE_STAMP_GROUP), &[("tool", name)]));
}
// An adjustment layer's content targeted (its thumbnail, or ⌘2 / `channel.target composite`):
// the Brush alerts instead of painting the mask that `paint_target` falls back to (#17640).
// Measured for the Brush only; the other tools keep painting the mask.
if !hidden && tool == Tool::Brush && adjustment_content_targeted(app) {
return Some(crate::i18n::fmt(tl!(CONTENT), &[("tool", name)]));
}
let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? };
Some(crate::i18n::fmt(tl!(template), &[("tool", name)]))
}
@@ -130,6 +138,21 @@ pub(crate) fn pixels_target(target: &serde_json::Value) -> bool {
}
}
/// Whether the active layer is an adjustment layer whose content, not its mask, is the target:
/// nothing names the mask (the Layers panel's mask thumbnail, ⌘\, mask view), and no alpha
/// channel, Quick Mask or filter mask takes the paint instead.
fn adjustment_content_targeted(app: &PhotocraftApp) -> bool {
use photocraft_engine::channel_cmds::ChannelTarget;
let Some(st) = app.session.active() else { return false };
if !crate::adjustment_layer_active(st) || app.ui.mask_target || st.channel_view.target == ChannelTarget::LayerMask {
return false;
}
if photocraft_engine::mask_view_cmds::current(st).is_some() {
return false;
}
matches!(crate::canvas::paint_target(app).as_str(), Some("mask" | "pixels"))
}
/// [`GROUP`] or [`LOCKED`] when `tool` can't paint the active layer's pixels.
fn layer_refusal(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
let st = app.session.active()?;
@@ -174,6 +197,10 @@ mod magic_eraser_refusal_alerts_tests;
#[path = "../brush_refusal_alert_tests.rs"]
pub(super) mod brush_refusal_alert_tests;
#[cfg(test)]
#[path = "../brush_adjustment_content_tests.rs"]
mod brush_adjustment_content_tests;
#[cfg(test)]
#[path = "../spot_healing_refusal_alert_tests.rs"]
mod spot_healing_refusal_alert_tests;