From 5e29ef92e2f95c67e7e579411123ecb3fb3fae11 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 08:01:25 -0600 Subject: [PATCH] Spot Healing Brush: alerts for a hidden layer, Lock All and a group A Spot Healing press on a hidden target layer, a layer with Lock All or a group now opens the reference application's alert with OK and heals nothing, instead of a status-bar message. On a hidden empty pixel layer with Sample All Layers off the press does nothing and says nothing. Lock transparent pixels still heals. Fixes #12581 --- crates/ui-egui/src/canvas/tools/mod.rs | 3 + .../src/spot_healing_refusal_alert_tests.rs | 61 +++++++++++++++++++ crates/ui-egui/src/tools/brush_refusal.rs | 22 +++++++ .../src/tools/remove_hidden_layer_tests.rs | 3 +- 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/spot_healing_refusal_alert_tests.rs diff --git a/crates/ui-egui/src/canvas/tools/mod.rs b/crates/ui-egui/src/canvas/tools/mod.rs index 4d03eb8d17..33dd38fec1 100644 --- a/crates/ui-egui/src/canvas/tools/mod.rs +++ b/crates/ui-egui/src/canvas/tools/mod.rs @@ -307,6 +307,9 @@ fn press_refused(app: &mut PhotocraftApp, tool: Tool) -> bool { /// case was measured: a layer inside a hidden group, a targeted mask, Sample All Layers and the other layer kinds keep /// the status-bar error. Hidden is checked before the lock, so a hidden layer with Lock All is quiet too. fn quiet_hidden_refusal(app: &PhotocraftApp, tool: Tool) -> bool { + if crate::brush_refusal::spot_healing_quiet(app, tool) { + return true; + } if tool != Tool::Remove || app.ui.tool_options.sample_all.remove || super::paint_target(app) != serde_json::json!("pixels") { return false; } diff --git a/crates/ui-egui/src/spot_healing_refusal_alert_tests.rs b/crates/ui-egui/src/spot_healing_refusal_alert_tests.rs new file mode 100644 index 0000000000..c82c38ccb8 --- /dev/null +++ b/crates/ui-egui/src/spot_healing_refusal_alert_tests.rs @@ -0,0 +1,61 @@ +//! #12581: when the Spot Healing Brush can't heal (a hidden target layer, Lock All, a group's +//! pixels), a press opens the reference application's alert with OK and changes nothing. On a hidden +//! empty pixel layer with Sample All Layers off the press does nothing and says nothing. Lock +//! transparent pixels is no refusal. + +use serde_json::json; + +use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke}; +use super::*; + +#[test] +fn a_hidden_target_layer() { + let mut app = app(Tool::SpotHealing); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + refused(&mut app, "Could not use the spot healing brush because the target layer is hidden."); + assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status); +} + +#[test] +fn lock_all() { + let mut app = app(Tool::SpotHealing); + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + refused(&mut app, "Could not use the spot healing brush because the layer is locked."); +} + +#[test] +fn a_group_is_active() { + let mut app = app(Tool::SpotHealing); + app.run("layer.new.group", json!({})).unwrap(); + refused(&mut app, "Could not use the spot healing brush because the pixels in a group cannot be edited without merging the group."); +} + +#[test] +fn a_hidden_empty_layer_with_sample_all_layers_off_does_nothing_quietly() { + let mut app = app(Tool::SpotHealing); + app.ui.tool_options.sample_all.spot_healing = false; + let empty = app.run("layer.new.layer", json!({"name": "Empty"})).unwrap()["layer"].as_u64().unwrap(); + app.run("layer.setProps", json!({"layer": empty, "visible": false})).unwrap(); + app.sync_views(); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app)); + assert_eq!(steps(&app), before, "no History step"); + assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error: {:?}", app.ui.status); +} + +#[test] +fn lock_transparent_pixels_still_heals() { + let mut app = app(Tool::SpotHealing); + app.run("layer.lockLayers", json!({"transparency": true})).unwrap(); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "no refusal: {:?}", alerts(&app)); + assert_eq!(steps(&app), before + 1, "the stroke was applied"); +} + +#[test] +fn the_shared_hidden_text_stays() { + assert_eq!(photocraft_engine::hidden_target::HIDDEN, "Could not complete your request because the target layer is hidden."); +} diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index ed76093d49..646b862914 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -46,6 +46,8 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { Tool::Sharpen => Some(tl!("sharpen tool")), Tool::Sponge => Some(tl!("sponge tool")), Tool::Smudge => Some(tl!("smudge tool")), + // The Spot Healing Brush (#12581). + Tool::SpotHealing => Some(tl!("spot healing brush")), Tool::ArtHistoryBrush => Some(tl!("art history brush")), Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")), _ => None, @@ -80,6 +82,10 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option { let pixel_layer = st.active_layer.and_then(|id| st.doc.layer(id)).is_some_and(|l| matches!(l.content, photocraft_doc::LayerContent::Raster(_))); return (!hidden && pixel_layer && layer_refusal(app, tool) == Some(LOCKED)).then(|| tl!(REMOVE_LOCKED).to_string()); } + // A Spot Healing press on a hidden empty pixel layer, Sample All Layers off, is refused quietly (#12581). + if hidden && spot_healing_quiet(app, tool) { + return None; + } let name = tool_name(app, tool)?; let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? }; Some(crate::i18n::fmt(tl!(template), &[("tool", name)])) @@ -107,10 +113,26 @@ fn locked(locks: photocraft_doc::Locks, tool: Tool) -> bool { locks.all || (matches!(tool, Tool::Sharpen | Tool::Sponge | Tool::Smudge | Tool::ArtHistoryBrush) && locks.pixels) } +/// A Spot Healing press on an empty pixel layer with Sample All Layers off (#12581): when that layer is hidden, the +/// press does nothing and says nothing, as in Photoshop; there is nothing to heal from. +pub(crate) fn spot_healing_quiet(app: &PhotocraftApp, tool: Tool) -> bool { + if tool != Tool::SpotHealing || app.ui.tool_options.sample_all.spot_healing || crate::canvas::paint_target(app) != json!("pixels") { + return false; + } + let Some(st) = app.session.active() else { return false }; + st.active_layer + .and_then(|id| st.doc.layer(id)) + .is_some_and(|l| matches!(l.content, photocraft_doc::LayerContent::Raster(_)) && l.surface().is_some_and(|s| s.content_bounds().is_empty())) +} + #[cfg(test)] #[path = "../brush_refusal_alert_tests.rs"] pub(super) mod brush_refusal_alert_tests; +#[cfg(test)] +#[path = "../spot_healing_refusal_alert_tests.rs"] +mod spot_healing_refusal_alert_tests; + #[cfg(test)] #[path = "../retouch_mode_refusal_alert_tests.rs"] mod retouch_mode_refusal_alert_tests; diff --git a/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs b/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs index 726a9821f6..be72d4affd 100644 --- a/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs +++ b/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs @@ -49,7 +49,8 @@ fn a_hidden_active_layer_is_quiet() { fn the_other_tools_keep_their_message() { refused(&mut hidden(Tool::Brush), "Could not use the brush tool because the target layer is hidden."); refused(&mut hidden(Tool::Smudge), "Could not use the smudge tool because the target layer is hidden."); - for tool in [Tool::Pencil, Tool::Eraser, Tool::SpotHealing, Tool::Healing, Tool::CloneStamp] { + // The Spot Healing Brush has its own alert since #12581. + for tool in [Tool::Pencil, Tool::Eraser, Tool::Healing, Tool::CloneStamp] { let mut app = hidden(tool); let before = steps(&app); stroke(&mut app);