fix(retouch): a Remove stroke on a smart object edits a new layer

The Remove tool is a pixel tool, so a press on a Smart Object layer opened
the rasterize prompt and nothing was removed until the layer was rasterized.
The reference application instead keeps the smart object intact: the fill
goes to a normal pixel layer named "Remove tool edits" directly above it,
even with Create new layer off, and the first such removal says so.

intercept lets the Remove tool's Smart Object press through to the tool;
the type, shape and fill prompts are unchanged. paint.remove treats a
Smart Object target as the new-layer case whatever "newLayer" says: the
hole is filled from the smart object's rendered pixels, read through
read_target_surface after the same pixel-lock check the painted case
makes, and the fill lands above it. Its precondition now admits a Smart
Object with pixels to sample. The options bar sends newLayer for that
target as well, so the params say what will happen, and after such a
removal the app posts the notice with its dismiss key, so the card offers
Do not show again and later removals stay quiet.

A second removal of the same smart object, Sample All Layers over one, and
the notice after it was closed are not measured in the reference: they
keep the new-layer path's behaviour, pinned by tests.

Fixes #12555
This commit is contained in:
hnoerenberg committed 2026-11-25 22:21:30 +01:00
1 parent 5f8d3d0fb2
commit 0be698eb85
8 files changed
+457 -25

No files matched your search

+2 -2
View File
@@ -357,9 +357,9 @@ pub fn specs() -> Vec<CommandSpec> {
menu: &[],
shortcut: None,
params: brush_params!(
r#","strokes":[[[x,y,pressure?],…]|{"points":[…],"size"?,"hardness"?,"spacing"?},…]? (several strokes removed together, as one job and one undo step, each with its own size, hardness and spacing when given; else "points"),"closeLoops":bool=true (a stroke around an object removes what it encloses),"sampleAllLayers":bool=false,"newLayer":bool=false (the fill goes to a new layer above the target, which stays as it was) → {"damage","layer"?} (a background job)"#
r#","strokes":[[[x,y,pressure?],…]|{"points":[…],"size"?,"hardness"?,"spacing"?},…]? (several strokes removed together, as one job and one undo step, each with its own size, hardness and spacing when given; else "points"),"closeLoops":bool=true (a stroke around an object removes what it encloses),"sampleAllLayers":bool=false,"newLayer":bool=false (the fill goes to a new layer above the target, which stays as it was; always on for a Smart Object layer) → {"damage","layer"?} (a background job)"#
),
enabled: has_pixel_layer,
enabled: remove::enabled,
run: remove::remove,
journal: true,
},
@@ -12,7 +12,9 @@
//! off, where the strokes collect and are applied together, so the fill sees every hole at once
//! instead of sampling from an area the next stroke is about to remove. With `newLayer` the fill
//! lands on a new layer above the target, only where the hole is, and the target stays as it was
//! (Photoshop's *Create a new layer*; with Sample All Layers it fills from the composite).
//! (Photoshop's *Create a new layer*; with Sample All Layers it fills from the composite). A Smart
//! Object layer is never painted into: its fill goes to a new layer above it, with the option on or
//! off, and the smart object keeps its content (#12555).
use super::content_aware_move::{Target, replace};
use super::patch::coverage;
@@ -20,7 +22,7 @@ use super::{
Document, EngineError, LayerId, PixelFormat, Rect, Region, Result, SampleLayers, Session, Stroke, Surface, Value, alpha_index, bad, clamp_samples,
composite_region, damage_json, flag, json, parse_brush, reject_huge_stroke, targets_pixels,
};
use photocraft_doc::Layer;
use photocraft_doc::{Layer, LayerContent};
const CMD: &str = "paint.remove";
@@ -60,6 +62,25 @@ struct Plan {
all_layers: bool,
/// The fill goes to a new layer above the target instead of into it.
new_layer: bool,
/// The target is a Smart Object with pixels to sample: its own content is only read, so
/// `new_layer` is on whatever the options bar says (#12555).
smart: bool,
}
/// The layer the stroke addresses, when it is a Smart Object whose rendered pixels can be sampled.
/// A Smart Object has no writable surface, so this is also what lets the command past the shared
/// "needs a pixel layer" precondition (#12555).
fn smart_object(doc: &Document, id: Option<LayerId>) -> bool {
id.and_then(|id| doc.layer(id)).is_some_and(|l| matches!(l.content, LayerContent::Smart(_)) && l.surface().is_some())
}
/// `paint.remove` runs where a stroke can go: the shared pixel-layer check, plus a Smart Object
/// layer, whose fill lands on a new layer above it (#12555).
pub(super) fn enabled(s: &Session) -> std::result::Result<(), String> {
match s.active() {
Some(d) if smart_object(&d.doc, d.active_layer) => Ok(()),
_ => super::has_pixel_layer(s),
}
}
/// The stroke's bounding box (points ± the brush radius), before any coverage is rendered.
@@ -132,9 +153,11 @@ fn plan(s: &Session, p: &Value) -> Result<Plan> {
let window = area.inflate(sampling_margin(area).min(MAX_MARGIN)).intersect(&canvas);
let close_loops = flag(p, "closeLoops", true);
let all_layers = flag(p, "sampleAllLayers", false) && targets_pixels(p);
// A mask or channel has no "above": the fill goes where the stroke went.
let new_layer = flag(p, "newLayer", false) && targets_pixels(p);
Ok(Plan { id, strokes, window, close_loops, all_layers, new_layer })
// A mask or channel has no "above": the fill goes where the stroke went. A Smart Object is never
// painted into, so its fill goes to a new layer above it whatever the option says (#12555).
let smart = targets_pixels(p) && smart_object(&d.doc, id);
let new_layer = (flag(p, "newLayer", false) || smart) && targets_pixels(p);
Ok(Plan { id, strokes, window, close_loops, all_layers, new_layer, smart })
}
/// The hole over the plan's window: the strokes' footprints, their enclosed areas and a margin,
@@ -181,7 +204,18 @@ fn run_remove(doc: &mut Document, plan: &Plan, p: &Value, ctx: &crate::jobs::Job
ctx.check()?;
let win = plan.window;
let (img, fmt) = {
let (surf, _) = crate::channel_cmds::target_surface(doc, plan.id, p)?;
// The sample comes from the layer the stroke addresses. A Smart Object has no writable
// surface, so its rendered pixels are read instead; the locks that keep a stroke off a
// Smart Object are the ones that keep it off a pixel layer (#12555).
let surf = if plan.smart {
if let Some(id) = plan.id {
crate::commands::check_pixels_unlocked(doc, id)?;
}
crate::channel_cmds::read_target_surface(doc, plan.id, p)?
} else {
let (surf, _) = crate::channel_cmds::target_surface(doc, plan.id, p)?;
surf
};
let fmt = surf.format();
let img = if plan.all_layers { composite_region(doc, None, SampleLayers::All, win, fmt) } else { Region::read(surf, win) };
(img, fmt)
@@ -276,3 +310,7 @@ pub(super) fn remove(s: &mut Session, p: &Value) -> Result<Value> {
#[cfg(test)]
#[path = "remove_new_layer_name_tests.rs"]
mod remove_new_layer_name_tests;
#[cfg(test)]
#[path = "remove_smart_object_tests.rs"]
mod remove_smart_object_tests;
@@ -0,0 +1,183 @@
//! The Remove tool on a Smart Object layer (#12555): its fill goes to a new normal layer named
//! "Remove tool edits" directly above the smart object, which keeps its own pixels, with Create
//! new layer off as well as on. The removal is one history step, and one undo takes the fill and
//! the new layer back together. A locked Smart Object, a layer mask target and a pixel layer keep
//! today's behaviour.
use super::*;
/// A grey layer with a dark square at 40..52 × 24..36, converted to a Smart Object over the
/// Background.
fn smart_session() -> Session {
let mut s = crate::session();
s.execute("file.new", json!({"width": 96, "height": 64, "depth": 8, "mode": "rgb"})).unwrap();
s.execute("layer.new.layer", json!({})).unwrap();
paint_square(&mut s);
s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
s
}
/// Fill the active pixel layer with grey and a dark square at 40..52 × 24..36.
fn paint_square(s: &mut Session) {
s.edit("setup", |doc, active| {
let b = doc.bounds();
let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap();
let fmt = surf.format();
let mut data = Vec::new();
for y in b.y0..b.y1 {
for x in b.x0..b.x1 {
let v = if (40..52).contains(&x) && (24..36).contains(&y) { 0.05 } else { 0.5 };
data.extend(photocraft_raster::from_rgba(&fmt, [v, v, v, 1.0]));
}
}
surf.write_region(b, &data);
Ok(())
})
.unwrap();
}
/// One stroke across the square, with the options bar's Create new layer as `new_layer`.
fn remove_stroke(s: &mut Session, new_layer: bool) -> Value {
s.execute("paint.remove", json!({"points": STROKE, "size": 16, "newLayer": new_layer})).unwrap()
}
const STROKE: [[i32; 2]; 2] = [[38, 30], [54, 30]];
fn order(s: &Session) -> Vec<LayerId> {
s.active().unwrap().doc.walk().into_iter().map(|(_, _, l)| l.id).collect()
}
fn name(s: &Session, id: LayerId) -> String {
s.active().unwrap().doc.layer(id).unwrap().name.clone()
}
fn kind(s: &Session, id: LayerId) -> &'static str {
s.active().unwrap().doc.layer(id).unwrap().content.kind_name()
}
/// The Smart Object's own pixels: its rendered cache.
fn pixels(s: &Session, id: LayerId) -> Surface {
s.active().unwrap().doc.layer(id).unwrap().surface().expect("the smart object holds rendered pixels").clone()
}
fn past(s: &Session) -> usize {
s.active().unwrap().history.past_len()
}
fn last_step(s: &Session) -> Option<String> {
s.active().unwrap().history.undo_label().map(str::to_string)
}
/// The removal's new layer, checked with Create new layer as `new_layer`: the smart object keeps
/// its kind and its pixels, the new layer sits directly above it and carries the fill.
fn check_edits_layer(new_layer: bool) {
let mut s = smart_session();
let smart = s.active().unwrap().active_layer.unwrap();
let below = order(&s);
let before = pixels(&s, smart);
let r = remove_stroke(&mut s, new_layer);
let id = LayerId(r["layer"].as_u64().unwrap_or_else(|| panic!("no new layer: {r}")));
assert_eq!(name(&s, id), "Remove tool edits", "newLayer {new_layer}");
assert_eq!(order(&s), [below, vec![id]].concat(), "the edits layer sits directly above the smart object");
assert_eq!(kind(&s, id), "Pixel", "a normal pixel layer");
assert_eq!(kind(&s, smart), "Smart Object", "the smart object stays a smart object");
assert_eq!(pixels(&s, smart), before, "the smart object's pixels are untouched, dark square and all");
assert!((pixels(&s, smart).rgba(46, 30)[0] - 0.05).abs() < 0.02, "the square is still there underneath: {:?}", pixels(&s, smart).rgba(46, 30));
let fill = pixels(&s, id);
assert!((fill.rgba(46, 30)[0] - 0.5).abs() < 0.03, "the new layer carries the fill sampled from the smart object: {:?}", fill.rgba(46, 30));
assert_eq!(fill.rgba(46, 30)[3], 1.0, "the fill is opaque where the hole was");
assert_eq!(s.active().unwrap().active_layer, Some(id), "the new layer is the active one");
}
#[test]
fn a_remove_stroke_on_a_smart_object_writes_to_remove_tool_edits_with_create_new_layer_off() {
check_edits_layer(false);
}
#[test]
fn a_remove_stroke_on_a_smart_object_writes_to_remove_tool_edits_with_create_new_layer_on() {
check_edits_layer(true);
}
#[test]
fn the_removal_is_one_step_and_one_undo_takes_the_fill_and_the_layer_back() {
for new_layer in [false, true] {
let mut s = smart_session();
let smart = s.active().unwrap().active_layer.unwrap();
let below = order(&s);
let before = pixels(&s, smart);
let steps = past(&s);
let r = remove_stroke(&mut s, new_layer);
let id = LayerId(r["layer"].as_u64().unwrap_or_else(|| panic!("no new layer: {r}")));
assert_eq!(past(&s), steps + 1, "newLayer {new_layer}: one history state");
assert_eq!(last_step(&s).as_deref(), Some("Remove Tool"), "newLayer {new_layer}");
s.execute("edit.undo", json!({})).unwrap();
assert_eq!(past(&s), steps, "newLayer {new_layer}: one undo takes the step back");
assert!(s.active().unwrap().doc.layer(id).is_none(), "newLayer {new_layer}: the fill left with its layer");
assert_eq!(order(&s), below, "newLayer {new_layer}: only the smart object is left where it was");
assert_eq!(kind(&s, smart), "Smart Object", "newLayer {new_layer}");
assert_eq!(pixels(&s, smart), before, "newLayer {new_layer}: undo gives the smart object its pixels back untouched");
assert_eq!(s.active().unwrap().active_layer, Some(smart), "newLayer {new_layer}: the smart object is active again");
}
}
/// A second removal of the same smart object: *not measured* in the reference, so the new-layer
/// path keeps doing what it does today, one more "Remove tool edits N" layer above it.
#[test]
fn a_second_stroke_on_the_smart_object_adds_another_edits_layer() {
let mut s = smart_session();
let bg = order(&s)[0];
let smart = s.active().unwrap().active_layer.unwrap();
let first = LayerId(remove_stroke(&mut s, false)["layer"].as_u64().unwrap());
// The edits layer became the active one, so the next stroke targets the smart object again.
s.execute("layer.select", json!({"layer": smart.0})).unwrap();
let r = remove_stroke(&mut s, false);
let second = LayerId(r["layer"].as_u64().unwrap());
assert_eq!(name(&s, second), "Remove tool edits 1", "the taken name is numbered, as with Create new layer");
assert_eq!(order(&s), vec![bg, smart, second, first], "the new layer sits directly above the smart object");
assert_eq!(kind(&s, smart), "Smart Object", "the smart object is still untouched");
}
/// A locked Smart Object keeps today's refusal: no edits layer and no stroke.
#[test]
fn a_locked_smart_object_still_refuses_the_stroke() {
let mut s = smart_session();
let stack = order(&s);
let (bg, smart) = (stack[0], stack[1]);
s.execute("layer.lockLayers", json!({"pixels": true})).unwrap();
let steps = past(&s);
let e = s.execute("paint.remove", json!({"points": STROKE, "size": 16})).unwrap_err().to_string();
assert!(e.contains("locked"), "{e}");
assert_eq!(past(&s), steps, "nothing was added to the history");
assert_eq!(order(&s), vec![bg, smart], "no layer was added");
assert_eq!(kind(&s, smart), "Smart Object");
}
/// A stroke on the smart object's layer mask keeps today's path: it fills the mask in place and
/// adds no layer.
#[test]
fn a_stroke_on_the_layer_mask_of_a_smart_object_adds_no_layer() {
let mut s = smart_session();
let smart = s.active().unwrap().active_layer.unwrap();
s.execute("layer.layerMask.revealAll", json!({})).unwrap();
let below = order(&s);
let r = s.execute("paint.remove", json!({"points": STROKE, "size": 16, "target": "mask"})).unwrap();
assert!(r.get("layer").is_none(), "a mask has no above: {r}");
assert_eq!(order(&s), below, "no new layer");
assert_eq!(kind(&s, smart), "Smart Object");
}
/// A pixel layer with Create new layer off keeps today's in-place fill and adds no layer.
#[test]
fn a_stroke_on_a_pixel_layer_without_create_new_layer_still_fills_in_place() {
let mut s = crate::session();
s.execute("file.new", json!({"width": 96, "height": 64, "depth": 8, "mode": "rgb"})).unwrap();
paint_square(&mut s);
let layer = s.active().unwrap().active_layer.unwrap();
let before = order(&s);
let r = remove_stroke(&mut s, false);
assert!(r.get("layer").is_none(), "{r}");
assert_eq!(order(&s), before, "no new layer");
assert_eq!(kind(&s, layer), "Pixel");
assert!((s.active().unwrap().doc.layer(layer).unwrap().surface().unwrap().rgba(46, 30)[0] - 0.5).abs() < 0.03, "filled in place");
}
+11 -4
View File
@@ -105,15 +105,18 @@ pub fn needed(app: &PhotocraftApp) -> Option<(Kind, photocraft_doc::LayerId)> {
/// A tool's pointer press: when it would paint a layer that must be rasterized first, open the
/// prompt, or drop the press (the Remove tool on a type layer), and return true (the tool must not
/// see the press).
/// see the press). The Remove tool on a Smart Object layer is the one press that goes on without an
/// answer: its fill lands on a new layer above the smart object, which keeps its content (#12555).
pub fn intercept(app: &mut PhotocraftApp, tool: Tool, x: f64, y: f64, pressure: f32) -> bool {
if !paints_pixels(app, tool) {
return false;
}
let Some((kind, layer)) = needed(app) else { return false };
// The reference's Remove tool ignores a type layer: no prompt and no stroke (#12553).
if tool == Tool::Remove && kind == Kind::Type {
return true;
match (tool, kind) {
// The reference's Remove tool ignores a type layer: no prompt and no stroke (#12553).
(Tool::Remove, Kind::Type) => return true,
(Tool::Remove, Kind::SmartObject) => return false,
_ => {}
}
open(app, kind, layer, tool, [x, y, f64::from(pressure)]);
true
@@ -291,3 +294,7 @@ mod rasterize_prompt_history_name_tests;
#[cfg(test)]
#[path = "../tools/remove_type_layer_tests.rs"]
mod remove_type_layer_tests;
#[cfg(test)]
#[path = "../tools/remove_smart_object_tests.rs"]
mod remove_smart_object_tests;
@@ -0,0 +1,165 @@
//! #12555: a Remove stroke on a Smart Object layer opens no rasterize prompt. Its fill goes to a
//! new normal layer "Remove tool edits" directly above the smart object, which keeps its pixels,
//! with the options bar's Create new layer off as well as on; the first such removal explains the
//! new layer in a notice that stays until closed, and Do not show again is remembered. Both Remove
//! modes go through this: filled at each release, and collected for the options bar's ✓.
use craft::keymap::Mods;
use egui::{Modifiers, vec2};
use egui_kittest::Harness;
use serde_json::json;
use super::Kind;
use super::tests::{app_with, past, prompt};
use crate::PhotocraftApp;
use crate::canvas::testing::{ToolEvent, tool_event};
use crate::retouch_ui;
use crate::state::Tool;
use photocraft_doc::LayerId;
/// A drag across the middle of the canvas, as a Remove stroke.
fn drag(app: &mut PhotocraftApp, y: f64) {
tool_event(app, ToolEvent::Down { x: 30.0, y, pressure: 1.0 }, Modifiers::NONE);
for i in 1..=12 {
tool_event(app, ToolEvent::Move { x: 30.0 + f64::from(i) * 5.0, y, pressure: 1.0 }, Modifiers::NONE);
}
tool_event(app, ToolEvent::Up { x: 90.0, y }, Modifiers::NONE);
}
fn layers(app: &PhotocraftApp) -> Vec<LayerId> {
app.session.active().unwrap().doc.walk().into_iter().map(|(_, _, l)| l.id).collect()
}
fn name(app: &PhotocraftApp, id: LayerId) -> String {
app.session.active().unwrap().doc.layer(id).unwrap().name.clone()
}
fn kind(app: &PhotocraftApp, id: LayerId) -> &'static str {
app.session.active().unwrap().doc.layer(id).unwrap().content.kind_name()
}
/// The Smart Object's own pixels: its rendered cache.
fn cache(app: &PhotocraftApp, id: LayerId) -> photocraft_raster::Surface {
app.session.active().unwrap().doc.layer(id).unwrap().surface().expect("the smart object holds rendered pixels").clone()
}
#[test]
fn a_remove_stroke_on_a_smart_object_asks_nothing_and_lands_on_the_edits_layer() {
for after_each in [true, false] {
let mut app = app_with(Kind::SmartObject);
app.ui.tool = Tool::Remove;
app.ui.tool_options.remove_after_each_stroke = after_each;
let stack = layers(&app);
let (bg, smart) = (stack[0], stack[1]);
let before = cache(&app, smart);
let steps = past(&app);
drag(&mut app, 40.0);
assert!(prompt(&app).is_none(), "{after_each}: the Remove tool asks nothing on a smart object");
assert!(app.framework.dialogs.is_empty(), "{after_each}: {:?}", app.framework.dialogs.open_dialogs());
if !after_each {
assert_eq!(layers(&app), vec![bg, smart], "{after_each}: the strokes wait for the options bar");
assert!(retouch_ui::remove_pending_commit(&mut app), "{after_each}: the ✓ applies the waiting strokes");
}
let after = layers(&app);
assert_eq!(after, vec![bg, smart, *after.last().unwrap()], "{after_each}: one new layer, directly above the smart object");
let edits = after[2];
assert_eq!(name(&app, edits), "Remove tool edits", "{after_each}");
assert_eq!(kind(&app, edits), "Pixel", "{after_each}: a normal layer");
assert_eq!(kind(&app, smart), "Smart Object", "{after_each}: the smart object stays editable");
assert_eq!(cache(&app, smart), before, "{after_each}: its pixels are untouched");
let filled = app.session.active().unwrap().doc.layer(edits).unwrap().surface().unwrap().rgba(60, 40);
assert!(filled[1] > 0.5 && filled[0] < 0.5, "{after_each}: the fill, sampled from the smart object, is on the new layer: {filled:?}");
assert_eq!(past(&app), steps + 1, "{after_each}: one history state");
assert!(!app.ui.status_error, "{after_each}: {}", app.ui.status);
}
}
/// The whole app, so the shell's pass hands the outbox to the window's toast queue: a document
/// whose active layer is a Smart Object over a filled pixel layer.
fn app_harness() -> Harness<'static, Box<PhotocraftApp>> {
let mut h = Harness::builder().with_size(vec2(1280.0, 800.0)).with_max_steps(32).build_eframe(|cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
let mut s = photocraft_engine::Session::new();
s.execute("file.new", json!({"width": 120, "height": 80})).unwrap();
s.execute("layer.new.layer", json!({})).unwrap();
s.execute("edit.fill", json!({"color": "#00ff00"})).unwrap();
s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), s, Default::default());
app.background_jobs = false;
app
});
h.run_steps(2);
h
}
/// One Remove stroke across the smart object, through the tool's own finish.
fn stroke(h: &mut Harness<'static, Box<PhotocraftApp>>) {
retouch_ui::finish_stroke(h.state_mut(), Tool::Remove, &[[30.0, 40.0, 1.0], [90.0, 40.0, 1.0]], Mods::default(), false);
h.run_steps(4);
}
/// The notice still waiting in the app's outbox, before a pass hands it to the window.
fn posted<'a>(h: &'a Harness<'static, Box<PhotocraftApp>>) -> Vec<&'a crate::notices::Notice> {
h.state().ui.notices.iter().filter(|notice| notice.title == retouch_ui::EDITS_NOTICE).collect()
}
/// The titles up: what the app has posted and the window's toast cards.
fn shown(h: &Harness<'static, Box<PhotocraftApp>>) -> Vec<String> {
crate::notices::shown(h.state(), &h.ctx).into_iter().map(|(title, _, _)| title).collect()
}
#[test]
fn the_first_removal_explains_the_new_layer_and_the_notice_stays_until_closed() {
let mut h = app_harness();
let smart = layers(h.state())[1];
retouch_ui::finish_stroke(h.state_mut(), Tool::Remove, &[[30.0, 40.0, 1.0], [90.0, 40.0, 1.0]], Mods::default(), false);
let posted = posted(&h);
assert_eq!(posted.len(), 1, "the removal posts one notice about the new layer");
assert!(posted[0].sticky, "it stays until closed");
assert_eq!(posted[0].dismiss_pref.as_deref(), Some(retouch_ui::EDITS_NOTICE_PREF), "its card offers Do not show again");
h.run_steps(4);
assert_eq!(shown(&h).iter().filter(|title| *title == retouch_ui::EDITS_NOTICE).count(), 1, "the card is on screen: {:?}", shown(&h));
// Sticky: the later passes keep it, and a second removal adds no second card.
h.run_steps(4);
assert_eq!(shown(&h).iter().filter(|title| *title == retouch_ui::EDITS_NOTICE).count(), 1, "the card stays until closed");
h.state_mut().run("layer.select", json!({"layer": smart.0})).unwrap();
h.run_steps(2);
stroke(&mut h);
assert_eq!(shown(&h).iter().filter(|title| *title == retouch_ui::EDITS_NOTICE).count(), 1, "the card is not stacked: {:?}", shown(&h));
assert_eq!(kind(h.state(), smart), "Smart Object", "both removals left the smart object intact");
}
/// The answer the card's Do not show again writes is the notice's dismiss key, stored in the dialog
/// preferences; with it stored, later removals bring no card back.
#[test]
fn do_not_show_again_keeps_the_notice_away_from_later_removals() {
let mut h = app_harness();
let smart = layers(h.state())[1];
h.state_mut().session.prefs.edit(|prefs| {
prefs.dialogs.insert(retouch_ui::EDITS_NOTICE_PREF.into(), serde_json::Value::Bool(true));
});
stroke(&mut h);
assert!(!shown(&h).iter().any(|title| title == retouch_ui::EDITS_NOTICE), "no card: {:?}", shown(&h));
// The removal itself is unaffected by the silenced notice.
let after = layers(h.state());
assert_eq!(after.len(), 3, "{after:?}: the edits layer still lands above the smart object");
assert_eq!(name(h.state(), after[2]), "Remove tool edits");
assert_eq!(kind(h.state(), smart), "Smart Object");
}
/// A pixel layer with Create new layer on keeps today's behaviour: the fill goes to a new layer and
/// nothing is noticed about it.
#[test]
fn a_removal_on_a_pixel_layer_with_create_new_layer_notices_nothing() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.background_jobs = false;
app.run("file.new", json!({"width": 120, "height": 80})).unwrap();
app.run("edit.fill", json!({"color": "#00ff00"})).unwrap();
app.ui.tool = Tool::Remove;
app.ui.tool_options.remove_new_layer = true;
let before = layers(&app);
drag(&mut app, 40.0);
assert_eq!(layers(&app).len(), before.len() + 1, "Create new layer adds the edits layer");
assert_eq!(name(&app, layers(&app)[1]), "Remove tool edits");
assert!(app.ui.notices.iter().all(|notice| notice.title != retouch_ui::EDITS_NOTICE), "no notice for a pixel layer: {:?}", app.ui.notices);
}
@@ -1,7 +1,7 @@
//! #12553: a press and drag with the Remove tool on a type layer does nothing, as in the
//! reference: no rasterize prompt, no stroke overlay, no message and no history state; the layer
//! stays type. The other pixel tools, and the Remove tool on shape, Smart Object and fill
//! layers, still ask to rasterize first.
//! stays type. The other pixel tools, and the Remove tool on shape and fill layers, still ask to
//! rasterize first; the Remove tool on a Smart Object layer has its own tests (#12555).
use egui::Modifiers;
@@ -46,8 +46,8 @@ fn brush_and_eraser_still_ask_on_a_type_layer() {
}
#[test]
fn remove_still_asks_on_shape_smart_object_and_fill_layers() {
for kind in [Kind::Shape, Kind::SmartObject, Kind::Fill] {
fn remove_still_asks_on_shape_and_fill_layers() {
for kind in [Kind::Shape, Kind::Fill] {
let mut app = app_with(kind);
app.ui.tool = Tool::Remove;
let before = past(&app);
+47 -8
View File
@@ -218,6 +218,9 @@ pub fn finish_stroke(app: &mut PhotocraftApp, tool: Tool, points: &[[f64; 3]], m
pub(crate) fn finish_stroke_with(app: &mut PhotocraftApp, tool: Tool, points: &[[f64; 3]], mods: Mods, line: bool, history: Option<Value>) -> bool {
let o = app.ui.tool_options.clone();
let pts = json!(points);
// Which Remove stroke writes its fill to a new layer above a Smart Object (#12555), settled
// before the run: the new layer is the active one afterwards.
let remove_edits = tool == Tool::Remove && remove_on_smart_object(app);
let (cmd, mut p): (&str, Value) = match tool {
Tool::SpotHealing => ("paint.spotHealing", json!({"type": o.spot_type, "sampleAllLayers": o.sample_all.spot_healing})),
Tool::Remove => {
@@ -225,7 +228,7 @@ pub(crate) fn finish_stroke_with(app: &mut PhotocraftApp, tool: Tool, points: &[
remove_pending_add(app, points);
return true;
}
("paint.remove", remove_params(&o, crate::canvas::paint_target(app).as_str() == Some("pixels")))
("paint.remove", remove_params(&o, crate::canvas::paint_target(app).as_str() == Some("pixels"), remove_edits))
}
Tool::MixerBrush => ("paint.mixerBrush", json!({})),
Tool::ColorReplacement => ("paint.colorReplacement", color_replacement_params(app)),
@@ -296,6 +299,8 @@ pub(crate) fn finish_stroke_with(app: &mut PhotocraftApp, tool: Tool, points: &[
Ok(r) if tool == Tool::PatternStamp => {
app.ui.pattern_stamp_phase = r.get("phase").and_then(|v| serde_json::from_value(v.clone()).ok()).filter(|_| o.pattern_stamp_aligned);
}
// The first removal that kept a Smart Object intact says where its fill went (#12555).
Ok(r) if remove_edits && r.get("layer").is_some() => notice_edits_layer(app),
Ok(_) => {}
// The Art History Brush's source refusals are alerts with OK, as the press-time ones, and
// not in the status bar as well (#12638). They were measured on a layer's pixels only: a
@@ -313,9 +318,36 @@ pub(crate) fn finish_stroke_with(app: &mut PhotocraftApp, tool: Tool, points: &[
true
}
/// `paint.remove` params from the options bar (without the strokes).
fn remove_params(o: &crate::state::ToolOptions, composite: bool) -> Value {
json!({"sampleAllLayers": o.sample_all.remove, "newLayer": o.remove_new_layer && composite})
/// `paint.remove` params from the options bar (without the strokes). A Smart Object is never
/// painted into: its fill always goes to a new layer above it (#12555).
fn remove_params(o: &crate::state::ToolOptions, composite: bool, smart_object: bool) -> Value {
json!({"sampleAllLayers": o.sample_all.remove, "newLayer": (o.remove_new_layer || smart_object) && composite})
}
/// Whether the Remove tool's stroke lands on a Smart Object layer, which keeps its own pixels while
/// the fill goes to a new layer above it (#12555).
fn remove_on_smart_object(app: &PhotocraftApp) -> bool {
app.session
.active()
.is_some_and(|st| st.active_layer.is_some_and(|id| st.doc.layer(id).is_some_and(|l| matches!(l.content, photocraft_doc::LayerContent::Smart(_)))))
}
/// What the reference says the first time the Remove tool keeps a Smart Object intact (#12555).
pub(crate) const EDITS_NOTICE: &str = "We created a new layer with your edits to help you make changes without affecting the original content.";
/// The notice's dismiss key: the card's Do not show again stores it, and the notice center then
/// keeps the notice out of later removals.
pub(crate) const EDITS_NOTICE_PREF: &str = "removeTool.newLayerNotice";
/// Post [`EDITS_NOTICE`]: it stays until closed, and one card at a time.
fn notice_edits_layer(app: &mut PhotocraftApp) {
if crate::notices::shown_titled(app, EDITS_NOTICE) {
return;
}
let id = crate::notices::post(app, EDITS_NOTICE, Vec::new(), craft::theme::variant::Tone::Neutral, Some(EDITS_NOTICE_PREF));
if let Some(notice) = app.ui.notices.iter_mut().find(|notice| notice.id == id) {
notice.sticky = true;
}
}
/// The selection a queued Remove stroke was drawn against. A later selection must not
@@ -364,13 +396,20 @@ pub fn remove_pending_commit(app: &mut PhotocraftApp) -> bool {
let strokes = std::mem::take(&mut app.remove_pending);
app.remove_trail = None;
app.remove_pending_target = None;
let mut p = remove_params(&app.ui.tool_options, crate::canvas::paint_target(app).as_str() == Some("pixels"));
// Taken before the run: a removal that writes to a new layer above a Smart Object makes that
// layer the active one (#12555).
let edits = remove_on_smart_object(app);
let mut p = remove_params(&app.ui.tool_options, crate::canvas::paint_target(app).as_str() == Some("pixels"), edits);
p["strokes"] = json!(strokes);
p["target"] = crate::canvas::paint_target(app);
app.ui.status.clear();
if let Err(e) = app.run("paint.remove", p) {
app.ui.status = e;
app.ui.status_error = true;
match app.run("paint.remove", p) {
Ok(r) if edits && r.get("layer").is_some() => notice_edits_layer(app),
Ok(_) => {}
Err(e) => {
app.ui.status = e;
app.ui.status_error = true;
}
}
true
}
+1 -1
View File
@@ -759,7 +759,7 @@ fn subset_remove_uses_the_existing_layer_without_losing_the_saved_new_layer_opti
assert_eq!(app.session.active().unwrap().doc.walk().len(), layers);
assert!(app.ui.tool_options.remove_new_layer);
app.run("channel.target", json!({"channel":"composite"})).unwrap();
assert_eq!(remove_params(&app.ui.tool_options, true)["newLayer"], json!(true));
assert_eq!(remove_params(&app.ui.tool_options, true, false)["newLayer"], json!(true));
}
#[test]