Merge branch 'bb-epic-color-replacement-mx3tl41i' of github.com:davidmann4/photocraft into bb-epic-color-replacement-mx3tl41i--17788-cr-cursor-pixel-group-locks

This commit is contained in:
David Mann committed 2026-12-01 06:09:48 +01:00
commit dd1aff337f
2 files changed
+89 -4

No files matched your search

@@ -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.");
}
+10 -4
View File
@@ -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;