From c8aa94678ec1ff9f1812654749dae9d301b447e1 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 07:41:44 -0600 Subject: [PATCH 1/2] Color Replacement: alerts for a hidden layer, Lock All and a group A Color Replacement press on a hidden target layer, a layer with Lock All or a group now opens the reference application's alert with OK and paints nothing, instead of a status-bar message. The group text is the tool's own. Lock transparent pixels still recolours. Fixes #11924 --- .../color_replacement_refusal_alert_tests.rs | 70 +++++++++++++++++++ crates/ui-egui/src/hidden_layer_tests.rs | 6 +- crates/ui-egui/src/tools/brush_refusal.rs | 12 +++- 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/color_replacement_refusal_alert_tests.rs diff --git a/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs b/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs new file mode 100644 index 0000000000..2ebbeb5b82 --- /dev/null +++ b/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs @@ -0,0 +1,70 @@ +//! #11924: when the Color Replacement tool can't paint (a hidden target layer, Lock All, a group), +//! a press opens the reference application's alert with OK and changes nothing. Lock transparent +//! pixels still recolours. Other tools keep their alerts. + +use serde_json::json; + +use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke}; +use super::*; +use crate::control::{ControlRequest, Reply, handle}; + +#[test] +fn a_hidden_target_layer() { + let mut app = app(Tool::ColorReplacement); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + refused(&mut app, "Could not use the Color Replacement tool because the target layer is hidden."); + assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status); + assert_eq!(photocraft_engine::hidden_target::HIDDEN, "Could not complete your request because the target layer is hidden.", "the shared text is unchanged"); +} + +#[test] +fn lock_all() { + let mut app = app(Tool::ColorReplacement); + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + refused(&mut app, "Could not use the Color Replacement tool because the layer is locked."); +} + +#[test] +fn a_group_is_active() { + let mut app = app(Tool::ColorReplacement); + app.run("layer.new.group", json!({})).unwrap(); + refused(&mut app, "Could not use the Color Replacement tool because the target is a group."); +} + +#[test] +fn lock_transparent_pixels_still_recolours() { + let mut app = app(Tool::ColorReplacement); + app.run("layer.lockLayers", json!({"transparency": true})).unwrap(); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "no refusal: {:?}", alerts(&app)); + assert_eq!(steps(&app), before + 1, "the stroke was applied"); +} + +#[test] +fn the_alert_is_listed_and_confirmed_over_the_control_channel() { + let ctx = egui::Context::default(); + let mut app = app(Tool::ColorReplacement); + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + stroke(&mut app); + let mut call = |method: &str, params: serde_json::Value| { + let (req, _rx) = ControlRequest::new(method, params); + match handle(&mut app, &ctx, &req) { + Reply::Done(v) => v, + _ => panic!("{method}: expected an immediate reply"), + } + }; + let inspect = call("ui.inspect", json!({})); + let dialog = &inspect["result"]["dialogs"][0]; + assert_eq!(dialog["fields"]["message"], "Could not use the Color Replacement tool because the layer is locked.", "{inspect}"); + assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true); + assert!(alerts(&app).is_empty()); +} + +#[test] +fn the_brush_keeps_its_group_text() { + let mut app = app(Tool::Brush); + app.run("layer.new.group", json!({})).unwrap(); + refused(&mut app, "Could not use the brush tool because the pixels in a group cannot be edited without merging the group."); +} diff --git a/crates/ui-egui/src/hidden_layer_tests.rs b/crates/ui-egui/src/hidden_layer_tests.rs index 338d4fe76b..8c7e152eae 100644 --- a/crates/ui-egui/src/hidden_layer_tests.rs +++ b/crates/ui-egui/src/hidden_layer_tests.rs @@ -82,11 +82,11 @@ fn painting_a_hidden_layer_is_refused_at_the_press() { let n = steps(&app); tool_event(&mut app, ToolEvent::Down { x: 30.0, y: 30.0, pressure: 1.0 }, egui::Modifiers::NONE); assert!(!crate::canvas::testing::in_gesture(&app) && app.live_stroke.is_none(), "{tool:?}: no stroke started"); - // The Brush (#11898) and the Classic gradient (#12017) say so in an alert, the other tools - // in the status bar. + // The Brush (#11898), the Classic gradient (#12017) and Color Replacement (#11924) say so in + // an alert, the other tools in the status bar. let alerts = alerts(&app); let alert = alerts.iter().any(|m| m.contains("target layer is hidden")); - if matches!(tool, Tool::Brush | Tool::Gradient) { + if matches!(tool, Tool::Brush | Tool::Gradient | Tool::ColorReplacement) { assert!(alert, "{tool:?}: {alerts:?}"); } else { assert!(app.ui.status.contains("target layer is hidden") && alerts.is_empty(), "{tool:?}: {}", app.ui.status); diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index ed76093d49..310f6d20d1 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -14,6 +14,8 @@ use crate::state::Tool; pub const HIDDEN: &str = "Could not use the {tool} because the target layer is hidden."; 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 Color Replacement tool's group alert (#11924): its own wording, not the Brush's [`GROUP`]. +pub const TARGET_GROUP: &str = "Could not use the {tool} because the target is a group."; /// 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."; @@ -39,7 +41,8 @@ fn mode_tool_name(tool: Tool) -> Option<&'static str> { /// The tool's name in the alerts, for the tools whose wording was measured: the Brush, the /// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Art History Brush -/// (#12638) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017). +/// (#12638), the Color Replacement tool (#11924) and the Classic gradient (the live Gradient makes a +/// fill layer and isn't measured, #12017). pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { match tool { Tool::Brush => Some(tl!("brush tool")), @@ -47,6 +50,7 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { Tool::Sponge => Some(tl!("sponge tool")), Tool::Smudge => Some(tl!("smudge tool")), Tool::ArtHistoryBrush => Some(tl!("art history brush")), + Tool::ColorReplacement => Some(tl!("Color Replacement tool")), Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")), _ => None, } @@ -82,6 +86,8 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option { } let name = tool_name(app, tool)?; let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? }; + // The Color Replacement tool says a group differently (#11924). + let template = if tool == Tool::ColorReplacement && template == GROUP { TARGET_GROUP } else { template }; Some(crate::i18n::fmt(tl!(template), &[("tool", name)])) } @@ -119,6 +125,10 @@ mod retouch_mode_refusal_alert_tests; #[path = "../smudge_refusal_alert_tests.rs"] mod smudge_refusal_alert_tests; +#[cfg(test)] +#[path = "../color_replacement_refusal_alert_tests.rs"] +mod color_replacement_refusal_alert_tests; + #[cfg(test)] #[path = "remove_hidden_layer_tests.rs"] mod remove_hidden_layer_tests; From 8796c756dd8fdf25e434de66ea41c26e29d772d2 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 14:39:34 -0600 Subject: [PATCH 2/2] Color Replacement: the hidden-layer alert is for pixel targets only (CodeRabbit on #16279) Test: a_hidden_layer_with_a_mask_target_keeps_the_status_bar_message. --- .../src/color_replacement_refusal_alert_tests.rs | 14 ++++++++++++++ crates/ui-egui/src/tools/brush_refusal.rs | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs b/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs index 2ebbeb5b82..26beacdade 100644 --- a/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs +++ b/crates/ui-egui/src/color_replacement_refusal_alert_tests.rs @@ -18,6 +18,20 @@ fn a_hidden_target_layer() { assert_eq!(photocraft_engine::hidden_target::HIDDEN, "Could not complete your request because the target layer is hidden.", "the shared text is unchanged"); } +/// A targeted layer mask on a hidden layer keeps the status-bar refusal: only a pixel target gets the alert (CodeRabbit +/// on #16279). +#[test] +fn a_hidden_layer_with_a_mask_target_keeps_the_status_bar_message() { + let mut app = app(Tool::ColorReplacement); + app.run("layer.layerMask.revealAll", json!({})).unwrap(); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + app.ui.mask_target = true; + stroke(&mut app); + assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app)); + assert!(app.ui.status_error, "the status bar says it: {:?}", app.ui.status); +} + #[test] fn lock_all() { let mut app = app(Tool::ColorReplacement); diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index 310f6d20d1..43e2eeca3e 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -85,7 +85,10 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option { return (!hidden && pixel_layer && layer_refusal(app, tool) == Some(LOCKED)).then(|| tl!(REMOVE_LOCKED).to_string()); } let name = tool_name(app, tool)?; - let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? }; + // The Color Replacement tool's hidden-layer alert is for a pixel target only: a mask target keeps the status-bar + // message it had (CodeRabbit on #16279). + let hidden_alert = hidden && (tool != Tool::ColorReplacement || crate::canvas::paint_target(app) == json!("pixels")); + let template = if hidden_alert { HIDDEN } else { layer_refusal(app, tool)? }; // The Color Replacement tool says a group differently (#11924). let template = if tool == Tool::ColorReplacement && template == GROUP { TARGET_GROUP } else { template }; Some(crate::i18n::fmt(tl!(template), &[("tool", name)]))