diff --git a/crates/engine-core/src/hidden_target.rs b/crates/engine-core/src/hidden_target.rs index efc56140ab0..82f450ebe9e 100644 --- a/crates/engine-core/src/hidden_target.rs +++ b/crates/engine-core/src/hidden_target.rs @@ -55,8 +55,9 @@ fn shown(doc: &Document, id: LayerId) -> bool { doc.path_of(id).is_some_and(|path| (1..=path.len()).all(|n| path.get(..n).and_then(|p| doc.layer_at(p)).is_some_and(|l| l.visible))) } -/// Why command `id` with `params` must not run: its target layer is hidden. `None` for other -/// commands, channel targets, and visible layers. +/// Why command `id` with `params` must not run: its target layer is hidden, or a Color Replacement +/// target it can't recolour ([`color_replacement_target`]). `None` for other commands, channel +/// targets, and visible layers. pub fn refusal(s: &Session, id: &str, params: &Value) -> Option<&'static str> { if !GATED.contains(&id) { return None; @@ -66,8 +67,11 @@ pub fn refusal(s: &Session, id: &str, params: &Value) -> Option<&'static str> { return None; } // The Color Replacement tool's target refusals come first: a hidden layer's mask gets them (#17782). - if id == "paint.colorReplacement" && color_replacement_target(s, ¶ms).is_some() { - return None; + // 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); } let st = s.active()?; if id == "layer.translate" && matches!(crate::commands::explicit_layer(s, ¶ms), Ok(None)) && st.selected_layers().len() > 1 { 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 f10ae5153c5..a97220837e1 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 @@ -93,3 +93,17 @@ fn every_colour_channel_is_the_composite_and_paints() { fn a_cmyk_channel_keeps_painting() { paints(&mut session_in(ColorMode::Cmyk), stroke(Some(json!({"color": 0})))); } + +/// A refused target is refused before a floating selection drops: the piece stays floating, and +/// neither the pixels nor History change. +#[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"); +}