From 18d30e30db5edc7c0781daf5cd9d8a05e066e8a6 Mon Sep 17 00:00:00 2001 From: x-labb <154824493+x-labb@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:13:31 +0100 Subject: [PATCH 1/4] fix(ui): the Healing Brush's refusals are the reference application's alerts (#12111) A Healing Brush press on a hidden target layer or a layer with Lock All only said why in the status bar. The reference application opens a modal alert with OK and paints nothing. Adds the Healing Brush to brush_refusal's tool_name table. A group keeps its own message (#12109), Lock Image Pixels and Lock position keep today's behaviour, and an Alt-click still only sets the clone source. --- .../src/healing_refusal_alert_tests.rs | 94 +++++++++++++++++++ crates/ui-egui/src/tools/brush_refusal.rs | 8 +- .../src/tools/remove_hidden_layer_tests.rs | 3 +- 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 crates/ui-egui/src/healing_refusal_alert_tests.rs diff --git a/crates/ui-egui/src/healing_refusal_alert_tests.rs b/crates/ui-egui/src/healing_refusal_alert_tests.rs new file mode 100644 index 0000000000..4b883a8299 --- /dev/null +++ b/crates/ui-egui/src/healing_refusal_alert_tests.rs @@ -0,0 +1,94 @@ +//! #12111: a Healing Brush press on a hidden target layer or a layer with Lock All opens the +//! reference application's alert with OK and paints nothing; an Alt-click still only sets the +//! source, a group keeps today's message (its own item, #12109) and the other tools keep theirs. + +use egui::Modifiers; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; +use crate::tools::brush_refusal::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke}; + +/// An Alt-click: the clone source. +fn set_source(app: &mut PhotocraftApp, x: f64, y: f64) { + tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, Modifiers::ALT); + tool_event(app, ToolEvent::Up { x, y }, Modifiers::ALT); +} + +#[test] +fn a_hidden_target_layer() { + let mut app = app(Tool::Healing); + set_source(&mut app, 50.0, 32.0); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + refused(&mut app, "Could not use the 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::Healing); + set_source(&mut app, 50.0, 32.0); + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + refused(&mut app, "Could not use the healing brush because the layer is locked."); +} + +#[test] +fn an_alt_click_on_a_hidden_or_locked_layer_only_sets_the_source() { + for lock in [false, true] { + let mut app = app(Tool::Healing); + let id = active(&app); + if lock { + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + } else { + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + } + let before = steps(&app); + set_source(&mut app, 50.0, 32.0); + assert!(alerts(&app).is_empty(), "lock {lock}: {:?}", alerts(&app)); + assert_eq!(app.ui.clone_source, Some([50.0, 32.0]), "lock {lock}: the source is set"); + assert_eq!(steps(&app), before, "lock {lock}: no history step"); + } +} + +#[test] +fn lock_image_pixels_and_lock_position_keep_todays_behaviour() { + for lock in ["pixels", "position"] { + let mut app = app(Tool::Healing); + set_source(&mut app, 50.0, 32.0); + app.run("layer.lockLayers", json!({ lock: true })).unwrap(); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "{lock}: {:?}", alerts(&app)); + } +} + +#[test] +fn a_group_keeps_its_own_message() { + let mut app = app(Tool::Healing); + set_source(&mut app, 50.0, 32.0); + app.run("layer.new.group", json!({})).unwrap(); + stroke(&mut app); + assert_eq!(alerts(&app), ["Could not use the Healing Brush Tool because the target layer is a group."]); +} + +#[test] +fn an_unlocked_visible_layer_still_heals() { + let mut app = app(Tool::Healing); + set_source(&mut app, 50.0, 32.0); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "{:?}", alerts(&app)); + assert_eq!(steps(&app), before + 1, "one Healing Brush state"); +} + +#[test] +fn the_clone_stamp_keeps_the_status_bar() { + let mut app = app(Tool::CloneStamp); + set_source(&mut app, 50.0, 32.0); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + stroke(&mut app); + assert!(alerts(&app).is_empty()); + assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN); +} diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index e08027ed65..80d501237f 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -38,7 +38,7 @@ fn mode_tool_name(tool: Tool) -> Option<&'static str> { } /// The tool's name in the alerts, for the tools whose wording was measured: the Brush, the -/// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Burn tool (#12672), the Art History Brush +/// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Burn tool (#12672), the Healing Brush (#12111), the Art History Brush /// (#12638) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017). pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { match tool { @@ -51,6 +51,7 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { // The Spot Healing Brush (#12581). Tool::SpotHealing => Some(tl!("spot healing brush")), Tool::Burn => Some(tl!("burn tool")), + Tool::Healing => Some(tl!("healing brush")), Tool::ArtHistoryBrush => Some(tl!("art history brush")), Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")), _ => None, @@ -118,7 +119,8 @@ fn layer_refusal(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { if crate::canvas::paint_target(app) != json!("pixels") { None } else if layer.is_group() { - Some(GROUP) + // A group is the Healing Brush's no-source alert (#12109), not this one. + (tool != Tool::Healing).then_some(GROUP) } else if locked(st.doc.effective_locks(layer.id), tool) { Some(LOCKED) } else { @@ -176,3 +178,5 @@ mod art_history_refusal_alert_tests; #[cfg(test)] #[path = "../burn_refusal_alert_tests.rs"] mod burn_refusal_alert_tests; +#[path = "../healing_refusal_alert_tests.rs"] +mod healing_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 be72d4affd..e448eec978 100644 --- a/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs +++ b/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs @@ -49,8 +49,9 @@ 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."); + refused(&mut hidden(Tool::Healing), "Could not use the healing brush because the target layer is hidden."); // The Spot Healing Brush has its own alert since #12581. - for tool in [Tool::Pencil, Tool::Eraser, Tool::Healing, Tool::CloneStamp] { + for tool in [Tool::Pencil, Tool::Eraser, Tool::CloneStamp] { let mut app = hidden(tool); let before = steps(&app); stroke(&mut app); From 82961c01bbd4e3d3a70a6e7b8d07a412c381e80f Mon Sep 17 00:00:00 2001 From: x-labb <154824493+x-labb@users.noreply.github.com> Date: Sat, 21 Nov 2026 14:33:12 +0100 Subject: [PATCH 2/4] fix(ui): a hidden group keeps the Healing Brush's status-bar error (#12111) The Healing Brush's alert is for a hidden or locked pixel layer. A hidden group, like a shown one, is the no-source case (#12109) and keeps today's messages. Adds a real-canvas test that an Alt-click on a hidden or locked layer still sets the clone source. --- crates/ui-egui/src/alt_click_tests.rs | 6 +-- .../src/healing_refusal_alert_tests.rs | 43 +++++++++++++++++++ crates/ui-egui/src/tools/brush_refusal.rs | 8 +++- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/alt_click_tests.rs b/crates/ui-egui/src/alt_click_tests.rs index 2232637c13..f5055e476d 100644 --- a/crates/ui-egui/src/alt_click_tests.rs +++ b/crates/ui-egui/src/alt_click_tests.rs @@ -11,7 +11,7 @@ use crate::app::framework::BuildApp as _; use crate::state::Tool; use craft::keymap::Mods; -fn harness(app: Box) -> Harness<'static, Box> { +pub(crate) fn harness(app: Box) -> Harness<'static, Box> { let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(vec2(900.0, 600.0)).build_app( |ui, app: &mut PhotocraftApp| { egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui)); @@ -48,7 +48,7 @@ fn button(h: &mut Harness<'static, Box>, p: Pos2, down: bool, m: } /// A click at document point (x, y) with `m` held from before the press until after the release. -fn click(h: &mut Harness<'static, Box>, x: f32, y: f32, m: Modifiers) { +pub(crate) fn click(h: &mut Harness<'static, Box>, x: f32, y: f32, m: Modifiers) { let p = screen(h, x, y); mods(h, m); h.event(egui::Event::PointerMoved(p)); @@ -78,7 +78,7 @@ fn drag(h: &mut Harness<'static, Box>, from: [f32; 2], to: [f32; } /// Two halves: red on the left, green on the right, on one background layer. -fn two_colours() -> Box { +pub(crate) fn two_colours() -> Box { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 200, "height": 100, "background": "white"})).unwrap(); app.run("select.rect", json!({"x": 0, "y": 0, "width": 100, "height": 100})).unwrap(); diff --git a/crates/ui-egui/src/healing_refusal_alert_tests.rs b/crates/ui-egui/src/healing_refusal_alert_tests.rs index 4b883a8299..dc1fd9d481 100644 --- a/crates/ui-egui/src/healing_refusal_alert_tests.rs +++ b/crates/ui-egui/src/healing_refusal_alert_tests.rs @@ -72,6 +72,18 @@ fn a_group_keeps_its_own_message() { assert_eq!(alerts(&app), ["Could not use the Healing Brush Tool because the target layer is a group."]); } +#[test] +fn a_hidden_group_keeps_the_status_bar_error() { + let mut app = app(Tool::Healing); + set_source(&mut app, 50.0, 32.0); + app.run("layer.new.group", json!({})).unwrap(); + let group = active(&app); + app.run("layer.setProps", json!({"layer": group, "visible": false})).unwrap(); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "{:?}", alerts(&app)); + assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN); +} + #[test] fn an_unlocked_visible_layer_still_heals() { let mut app = app(Tool::Healing); @@ -92,3 +104,34 @@ fn the_clone_stamp_keeps_the_status_bar() { assert!(alerts(&app).is_empty()); assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN); } + +/// Through the real canvas: a press reaches the tool through the host's preflight, which is where +/// the refusals run, so the Alt-click that sets the source must get past it. +mod canvas { + use egui::Modifiers; + use serde_json::json; + + use crate::alt_click_tests::{click, harness, two_colours}; + use crate::state::Tool; + use crate::tools::brush_refusal::brush_refusal_alert_tests::alerts; + + #[test] + fn an_alt_click_on_a_hidden_or_locked_layer_sets_the_source_and_a_click_is_refused() { + for lock in [false, true] { + let mut h = harness(two_colours()); + h.state_mut().ui.tool = Tool::Healing; + let id = h.state().session.active().unwrap().active_layer.unwrap().0; + if lock { + h.state_mut().run("layer.lockLayers", json!({"all": true})).unwrap(); + } else { + h.state_mut().run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + } + click(&mut h, 150.0, 50.0, Modifiers::ALT); + assert!(h.state().session.presets.clone.active().source.is_some(), "lock {lock}: the source is set"); + assert!(alerts(h.state()).is_empty(), "lock {lock}: no alert: {:?}", alerts(h.state())); + // A plain click is still refused. + click(&mut h, 50.0, 50.0, Modifiers::NONE); + assert_eq!(alerts(h.state()).len(), 1, "lock {lock}: {:?}", alerts(h.state())); + } + } +} diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index 80d501237f..297d11ebb8 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -96,6 +96,11 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option { if hidden && tool == Tool::ArtHistoryBrush && !pixels_target(&crate::canvas::paint_target(app)) { return None; } + // A group is the Healing Brush's no-source alert (#12109), hidden or not: it keeps today's + // messages (the status bar for a hidden one, `refuse_group`'s alert for a shown one). + if tool == Tool::Healing && app.session.active().and_then(|st| st.doc.layer(st.active_layer?)).is_some_and(photocraft_doc::Layer::is_group) { + return None; + } let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? }; Some(crate::i18n::fmt(tl!(template), &[("tool", name)])) } @@ -119,8 +124,7 @@ fn layer_refusal(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { if crate::canvas::paint_target(app) != json!("pixels") { None } else if layer.is_group() { - // A group is the Healing Brush's no-source alert (#12109), not this one. - (tool != Tool::Healing).then_some(GROUP) + Some(GROUP) } else if locked(st.doc.effective_locks(layer.id), tool) { Some(LOCKED) } else { From fabff1a28a2e872d237112f923cc6b59ff50632c Mon Sep 17 00:00:00 2001 From: x-labb <154824493+x-labb@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:47:53 +0100 Subject: [PATCH 3/4] Healing alert tests: reach the presets through PresetsExt (#12111) --- crates/ui-egui/src/healing_refusal_alert_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/healing_refusal_alert_tests.rs b/crates/ui-egui/src/healing_refusal_alert_tests.rs index dc1fd9d481..c6f163229f 100644 --- a/crates/ui-egui/src/healing_refusal_alert_tests.rs +++ b/crates/ui-egui/src/healing_refusal_alert_tests.rs @@ -109,6 +109,7 @@ fn the_clone_stamp_keeps_the_status_bar() { /// the refusals run, so the Alt-click that sets the source must get past it. mod canvas { use egui::Modifiers; + use photocraft_engine::presets::PresetsExt; use serde_json::json; use crate::alt_click_tests::{click, harness, two_colours}; @@ -127,7 +128,7 @@ mod canvas { h.state_mut().run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); } click(&mut h, 150.0, 50.0, Modifiers::ALT); - assert!(h.state().session.presets.clone.active().source.is_some(), "lock {lock}: the source is set"); + assert!(h.state().session.presets().clone.active().source.is_some(), "lock {lock}: the source is set"); assert!(alerts(h.state()).is_empty(), "lock {lock}: no alert: {:?}", alerts(h.state())); // A plain click is still refused. click(&mut h, 50.0, 50.0, Modifiers::NONE); From bb33b25bd6d5ba1404aca54c660b8bb48b1b59ea Mon Sep 17 00:00:00 2001 From: x-labb <154824493+x-labb@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:05:17 +0100 Subject: [PATCH 4/4] Healing alert tests: gate the test module (#12111) --- crates/ui-egui/src/tools/brush_refusal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index 297d11ebb8..9cca2401d3 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -182,5 +182,7 @@ mod art_history_refusal_alert_tests; #[cfg(test)] #[path = "../burn_refusal_alert_tests.rs"] mod burn_refusal_alert_tests; + +#[cfg(test)] #[path = "../healing_refusal_alert_tests.rs"] mod healing_refusal_alert_tests;