From 471cdf4646c97af5a4aadae49801409a4e5fcfd8 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 1 Dec 2026 12:05:13 +0100 Subject: [PATCH] Color Replacement: refuse an alpha channel or Quick Mask target at admission too Co-Authored-By: Claude Opus 5.5 --- crates/engine-core/src/hidden_target.rs | 9 ++++--- .../color_replacement_channel_target_tests.rs | 26 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/engine-core/src/hidden_target.rs b/crates/engine-core/src/hidden_target.rs index 82f450ebe9..5422f1e2e7 100644 --- a/crates/engine-core/src/hidden_target.rs +++ b/crates/engine-core/src/hidden_target.rs @@ -63,16 +63,17 @@ pub fn refusal(s: &Session, id: &str, params: &Value) -> Option<&'static str> { return None; } let params = crate::channel_cmds::inject_target(s, id, params.clone()); - if crate::channel_cmds::is_channel_target(¶ms) { - return None; - } - // The Color Replacement tool's target refusals come first: a hidden layer's mask gets them (#17782). + // The Color Replacement tool's target refusals come first: a hidden layer's mask gets them (#17782), + // and so do an alpha channel and the Quick Mask, which other commands may paint. // Admission returns them, so a refused stroke leaves a floating selection floating, with no History step. if id == "paint.colorReplacement" && let Some(why) = color_replacement_target(s, ¶ms) { return Some(why); } + if crate::channel_cmds::is_channel_target(¶ms) { + return None; + } let st = s.active()?; if id == "layer.translate" && matches!(crate::commands::explicit_layer(s, ¶ms), Ok(None)) && st.selected_layers().len() > 1 { return None; diff --git a/crates/engine-paint/src/cmd/color_replacement_channel_target_tests.rs b/crates/engine-paint/src/cmd/color_replacement_channel_target_tests.rs index a97220837e..d092f4ed56 100644 --- a/crates/engine-paint/src/cmd/color_replacement_channel_target_tests.rs +++ b/crates/engine-paint/src/cmd/color_replacement_channel_target_tests.rs @@ -6,7 +6,7 @@ use photocraft_color::{Color, ColorMode, SampleType}; use photocraft_doc::{Document, Size}; -use photocraft_engine_core::hidden_target::{COLOR_REPLACEMENT_COMPOSITE, COLOR_REPLACEMENT_MASK}; +use photocraft_engine_core::hidden_target::{COLOR_REPLACEMENT_ALPHA, COLOR_REPLACEMENT_COMPOSITE, COLOR_REPLACEMENT_MASK}; use serde_json::json; use super::*; @@ -95,15 +95,21 @@ fn a_cmyk_channel_keeps_painting() { } /// A refused target is refused before a floating selection drops: the piece stays floating, and -/// neither the pixels nor History change. +/// neither the pixels nor History change. Also for an alpha channel and the Quick Mask, which the +/// hidden-layer check skips. #[test] fn a_refused_target_leaves_a_floating_selection_floating() { - let mut s = session(); - s.execute("select.all", json!({})).unwrap(); - s.execute("select.float", json!({"dx": 8, "dy": 0, "copy": true})).unwrap(); - let before = snapshot(&s); - let err = s.execute("paint.colorReplacement", stroke(Some(json!({"color": 0})))).unwrap_err().to_string(); - assert_eq!(err, COLOR_REPLACEMENT_MASK); - assert!(snapshot(&s) == before, "nothing dropped or painted, no History state"); - assert!(crate::float_cmds::floating(s.active().unwrap()).is_some(), "the piece still floats"); + for (target, why) in + [(json!({"color": 0}), COLOR_REPLACEMENT_MASK), (json!({"channel": 0}), COLOR_REPLACEMENT_ALPHA), (json!("quickMask"), COLOR_REPLACEMENT_ALPHA)] + { + let mut s = session(); + s.execute("channel.new", json!({})).unwrap(); + s.execute("select.all", json!({})).unwrap(); + s.execute("select.float", json!({"dx": 8, "dy": 0, "copy": true})).unwrap(); + let before = snapshot(&s); + let err = s.execute("paint.colorReplacement", stroke(Some(target.clone()))).unwrap_err().to_string(); + assert_eq!(err, why, "{target}"); + assert!(snapshot(&s) == before, "{target}: nothing dropped or painted, no History state"); + assert!(crate::float_cmds::floating(s.active().unwrap()).is_some(), "{target}: the piece still floats"); + } }