From ac27a5f445e12c31ed5bb4668c1752e591537da4 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 05:08:38 +0100 Subject: [PATCH] Color Replacement: Lock image pixels opens the "layer is locked" alert (#17787) A press with the Color Replacement tool on a layer whose image pixels are locked, by its own lock or by a locked group or artboard around it, now opens the alert with OK and paints nothing, like Lock All. Alt+click still samples; Lock transparent pixels, Lock position and the artboard lock still paint; a hidden layer and a group keep their alerts first. Co-Authored-By: Claude Opus 5.5 --- ...lor_replacement_lock_pixels_alert_tests.rs | 79 +++++++++++++++++++ crates/ui-egui/src/tools/brush_refusal.rs | 14 +++- 2 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/color_replacement_lock_pixels_alert_tests.rs diff --git a/crates/ui-egui/src/color_replacement_lock_pixels_alert_tests.rs b/crates/ui-egui/src/color_replacement_lock_pixels_alert_tests.rs new file mode 100644 index 0000000000..fa261a1f05 --- /dev/null +++ b/crates/ui-egui/src/color_replacement_lock_pixels_alert_tests.rs @@ -0,0 +1,79 @@ +//! #17787: Lock image pixels refuses the Color Replacement tool like Lock All, on the layer itself +//! or from a locked group or artboard around it: a press opens the "layer is locked" alert, paints +//! nothing and adds no History step; a drag opens one alert. Alt+click still samples the +//! foreground. Lock transparent pixels, Lock position and the artboard lock still paint; a hidden +//! layer and a group keep their own alerts first. + +use egui::Modifiers; +use serde_json::json; + +use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke}; +use super::*; +use crate::canvas::{ToolEvent, tool_event}; + +const LOCKED: &str = "Could not use the Color Replacement tool because the layer is locked."; + +#[test] +fn lock_image_pixels_alone_and_with_other_locks() { + for locks in [json!({"pixels": true}), json!({"pixels": true, "position": true}), json!({"pixels": true, "transparency": true})] { + let mut app = app(Tool::ColorReplacement); + app.run("layer.lockLayers", locks.clone()).unwrap(); + // `refused` drags across the layer: one alert, nothing painted. + refused(&mut app, LOCKED); + } +} + +/// A lock on the group or artboard around the active layer refuses the layer too. +#[test] +fn a_locked_group_or_artboard_around_the_layer() { + for (wrap, lock) in + [("layer.groupLayers", "all"), ("layer.groupLayers", "pixels"), ("layer.new.artboardFromLayers", "all"), ("layer.new.artboardFromLayers", "pixels")] + { + let mut app = app(Tool::ColorReplacement); + let child = active(&app); + app.run(wrap, json!({})).unwrap(); + assert_ne!(active(&app), child, "{wrap}: the new container is active"); + app.run("layer.lockLayers", json!({ lock: true })).unwrap(); + app.run("layer.select", json!({"layer": child})).unwrap(); + refused(&mut app, LOCKED); + } +} + +#[test] +fn alt_click_on_a_locked_layer_samples_the_foreground() { + let mut app = app(Tool::ColorReplacement); + app.run("layer.lockLayers", json!({"pixels": true})).unwrap(); + let before = steps(&app); + tool_event(&mut app, ToolEvent::Down { x: 30.0, y: 30.0, pressure: 1.0 }, Modifiers::ALT); + tool_event(&mut app, ToolEvent::Up { x: 30.0, y: 30.0 }, Modifiers::ALT); + assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app)); + assert_eq!(steps(&app), before, "no History step"); + let fg = app.session.tools.foreground; + assert!(fg[0] > 0.8 && fg[1] < 0.2, "the foreground took the layer's red: {fg:?}"); +} + +#[test] +fn locks_that_leave_the_pixels_editable_still_paint() { + for lock in ["transparency", "position", "artboard"] { + let mut app = app(Tool::ColorReplacement); + app.run("layer.lockLayers", json!({ lock: true })).unwrap(); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "{lock}: no refusal: {:?}", alerts(&app)); + assert_eq!(steps(&app), before + 1, "{lock}: the stroke was applied"); + } +} + +#[test] +fn hidden_and_group_come_before_the_lock() { + let mut app = app(Tool::ColorReplacement); + let id = active(&app); + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + 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."); + + let mut app = super::brush_refusal_alert_tests::app(Tool::ColorReplacement); + app.run("layer.groupLayers", json!({})).unwrap(); + app.run("layer.lockLayers", json!({"pixels": true})).unwrap(); + refused(&mut app, "Could not use the Color Replacement tool because the target is a group."); +} diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index 8a20a009a5..c4993b2ddc 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -180,12 +180,14 @@ fn layer_refusal(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { } /// Whether `locks` refuse `tool`: Lock All, and for the Sharpen, Sponge, Smudge and Burn tools, the -/// Art History Brush, the Magic Eraser and the Paint Bucket (#12537) Lock Image Pixels as well -/// (measured for them; the Brush keeps today's behaviour there). +/// Art History Brush, the Magic Eraser, the Paint Bucket (#12537) and the Color Replacement tool (#17787) +/// Lock Image Pixels as well (measured for them; the Brush keeps today's behaviour there). fn locked(locks: photocraft_doc::Locks, tool: Tool) -> bool { locks.all - || (matches!(tool, Tool::Sharpen | Tool::Sponge | Tool::Smudge | Tool::Burn | Tool::ArtHistoryBrush | Tool::MagicEraser | Tool::PaintBucket) - && locks.pixels) + || (matches!( + tool, + Tool::Sharpen | Tool::Sponge | Tool::Smudge | Tool::Burn | Tool::ArtHistoryBrush | Tool::MagicEraser | Tool::PaintBucket | Tool::ColorReplacement + ) && locks.pixels) } /// A Spot Healing press on an empty pixel layer with Sample All Layers off (#12581): when that layer is hidden, the @@ -228,6 +230,10 @@ mod smudge_refusal_alert_tests; #[path = "../color_replacement_refusal_alert_tests.rs"] mod color_replacement_refusal_alert_tests; +#[cfg(test)] +#[path = "../color_replacement_lock_pixels_alert_tests.rs"] +mod color_replacement_lock_pixels_alert_tests; + #[cfg(test)] #[path = "color_replacement_target_alerts_tests.rs"] mod color_replacement_target_alerts_tests;