From 9533f8805accca054a4a0106b9b3315f0e714e8c Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:57:50 +0100 Subject: [PATCH 1/2] Remove tool: name the History step "Remove Tool" (#12541) Every applied removal (one stroke, waiting strokes applied together, Sample All Layers, Create new layer, any colour mode and depth) now adds one History step named "Remove Tool", as the reference application does. The command id, its params and the job's progress label are unchanged. --- crates/engine/src/cmd/retouch_cmds.rs | 3 + crates/engine/src/cmd/retouch_cmds/remove.rs | 8 +- .../retouch_cmds/remove_history_name_tests.rs | 92 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds.rs b/crates/engine/src/cmd/retouch_cmds.rs index 115b8c40f91..b11e9f6a335 100644 --- a/crates/engine/src/cmd/retouch_cmds.rs +++ b/crates/engine/src/cmd/retouch_cmds.rs @@ -400,3 +400,6 @@ mod tests; #[cfg(test)] mod patch_history_names_tests; + +#[cfg(test)] +mod remove_history_name_tests; diff --git a/crates/engine/src/cmd/retouch_cmds/remove.rs b/crates/engine/src/cmd/retouch_cmds/remove.rs index 777b1131f93..c92505dcb8a 100644 --- a/crates/engine/src/cmd/retouch_cmds/remove.rs +++ b/crates/engine/src/cmd/retouch_cmds/remove.rs @@ -24,6 +24,10 @@ use photocraft_doc::Layer; const CMD: &str = "paint.remove"; +/// The History step of an applied removal, as Photoshop names it (#12541). The job and its +/// progress keep the command's label. +const HISTORY: &str = "Remove Tool"; + /// Largest stroke, in pixels of its bounding box (as the Patch Tool's and Content-Aware Move's). /// Checked before the stroke's coverage is rendered, which allocates its whole bounding box, also /// where it leaves the canvas. @@ -247,7 +251,7 @@ pub(super) fn remove(s: &mut Session, p: &Value) -> Result { move |s, filled| { let Some((out, hole)) = filled else { return Ok(json!({"changed": false})) }; if new_layer { - let (damage, nid) = s.edit(label, |doc, active| { + let (damage, nid) = s.edit(HISTORY, |doc, active| { let r = fill_to_new_layer(doc, id, &out, &hole)?; *active = Some(r.1); Ok(r) @@ -255,7 +259,7 @@ pub(super) fn remove(s: &mut Session, p: &Value) -> Result { s.hint_damage(damage); return Ok(json!({ "damage": damage_json(damage), "layer": nid.0 })); } - let damage = s.edit(label, |doc, _| replace(doc, Target { id, all_layers: false }, &p, &out, &hole))?; + let damage = s.edit(HISTORY, |doc, _| replace(doc, Target { id, all_layers: false }, &p, &out, &hole))?; s.hint_damage(damage); Ok(json!({ "damage": damage_json(damage) })) }, diff --git a/crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs b/crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs new file mode 100644 index 00000000000..bec64fbb0f8 --- /dev/null +++ b/crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs @@ -0,0 +1,92 @@ +//! History step name of the Remove Tool (#12541): every applied removal adds exactly one step +//! named "Remove Tool", whatever the strokes, options, colour mode or bit depth. + +use super::*; +use crate::jobs::Started; + +/// A flat grey layer with a dark square at 40..52 × 24..36. +fn square_session(depth: u64, mode: &str) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 96, "height": 64, "depth": depth, "mode": mode})).unwrap(); + 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(); + s +} + +fn past(s: &Session) -> usize { + s.active().unwrap().history.past_len() +} + +fn last_step(s: &Session) -> Option { + s.active().unwrap().history.undo_label().map(str::to_string) +} + +const STROKE: [[i32; 2]; 2] = [[38, 30], [54, 30]]; + +#[test] +fn one_stroke_is_one_step_named_remove_tool_in_every_mode_and_depth() { + for (depth, mode) in [(8, "rgb"), (16, "rgb"), (32, "rgb"), (8, "cmyk"), (16, "gray"), (16, "lab")] { + let mut s = square_session(depth, mode); + let steps = past(&s); + s.execute("paint.remove", json!({"points": STROKE, "size": 16})).unwrap(); + assert_eq!(past(&s), steps + 1, "{mode}/{depth}: one step"); + assert_eq!(last_step(&s).as_deref(), Some("Remove Tool"), "{mode}/{depth}"); + } +} + +#[test] +fn waiting_strokes_applied_together_are_one_step_named_remove_tool() { + let mut s = square_session(8, "rgb"); + let steps = past(&s); + s.execute("paint.remove", json!({"strokes": [[[38, 30], [45, 30]], [[47, 30], [54, 30]]], "size": 16})).unwrap(); + assert_eq!(past(&s), steps + 1); + assert_eq!(last_step(&s).as_deref(), Some("Remove Tool")); +} + +#[test] +fn sample_all_layers_and_create_new_layer_are_one_step_named_remove_tool() { + let mut s = square_session(8, "rgb"); + s.execute("layer.new.layer", json!({})).unwrap(); + let steps = past(&s); + s.execute("paint.remove", json!({"points": STROKE, "size": 16, "sampleAllLayers": true})).unwrap(); + assert_eq!(past(&s), steps + 1, "sampleAllLayers"); + assert_eq!(last_step(&s).as_deref(), Some("Remove Tool"), "sampleAllLayers"); + + let mut s = square_session(8, "rgb"); + let layers = s.active().unwrap().doc.layer_count(); + let steps = past(&s); + let v = s.execute("paint.remove", json!({"points": STROKE, "size": 16, "newLayer": true})).unwrap(); + assert!(v["layer"].is_u64(), "{v}"); + assert_eq!(s.active().unwrap().doc.layer_count(), layers + 1, "newLayer adds the result layer"); + assert_eq!(past(&s), steps + 1, "newLayer"); + assert_eq!(last_step(&s).as_deref(), Some("Remove Tool"), "newLayer"); +} + +#[test] +fn the_background_job_records_remove_tool_and_undo_redo_keep_the_name() { + let mut s = square_session(8, "rgb"); + let steps = past(&s); + let Started::Job(job) = s.start("paint.remove", json!({"points": STROKE, "size": 16})).unwrap() else { + panic!("paint.remove runs as a background job"); + }; + s.wait_job(job).unwrap(); + assert_eq!(past(&s), steps + 1); + assert_eq!(last_step(&s).as_deref(), Some("Remove Tool")); + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(s.active().unwrap().history.redo_label(), Some("Remove Tool")); + s.execute("edit.redo", json!({})).unwrap(); + assert_eq!(last_step(&s).as_deref(), Some("Remove Tool")); +} From 85743288121f7fdbd78a5ba0fe22a252dc773e37 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:40:54 +0100 Subject: [PATCH 2/2] ci: rerun