Color Replacement: refuse an alpha channel or Quick Mask target at admission too

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-12-01 12:05:13 +01:00
1 parent 4674495026
commit 471cdf4646
2 files changed
+21 -14

No files matched your search

+5 -4
View File
@@ -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(&params) {
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, &params)
{
return Some(why);
}
if crate::channel_cmds::is_channel_target(&params) {
return None;
}
let st = s.active()?;
if id == "layer.translate" && matches!(crate::commands::explicit_layer(s, &params), Ok(None)) && st.selected_layers().len() > 1 {
return None;
@@ -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");
}
}