Merge #15962 into the merge queue batch

fix(ui): the Healing Brush's refusals are the reference application's alerts (#12111)
This commit is contained in:
David Mann committed 2026-11-27 00:59:34 +01:00
commit 2d2c6ce5a2
4 files changed
+154 -5

No files matched your search

+3 -3
View File
@@ -11,7 +11,7 @@ use crate::app::framework::BuildApp as _;
use crate::state::Tool;
use craft::keymap::Mods;
fn harness(app: Box<PhotocraftApp>) -> Harness<'static, Box<PhotocraftApp>> {
pub(crate) fn harness(app: Box<PhotocraftApp>) -> Harness<'static, Box<PhotocraftApp>> {
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<PhotocraftApp>>, 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<PhotocraftApp>>, x: f32, y: f32, m: Modifiers) {
pub(crate) fn click(h: &mut Harness<'static, Box<PhotocraftApp>>, 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<PhotocraftApp>>, from: [f32; 2], to: [f32;
}
/// Two halves: red on the left, green on the right, on one background layer.
fn two_colours() -> Box<PhotocraftApp> {
pub(crate) fn two_colours() -> Box<PhotocraftApp> {
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();
@@ -0,0 +1,138 @@
//! #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 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);
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);
}
/// 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 photocraft_engine::presets::PresetsExt;
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()));
}
}
}
+11 -1
View File
@@ -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,
@@ -95,6 +96,11 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
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)]))
}
@@ -176,3 +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;
@@ -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);