From 60d0895c270a9ca85111fbfa3501ab9cc5dcb708 Mon Sep 17 00:00:00 2001 From: SBaksa Date: Sun, 8 Nov 2026 14:32:37 +1100 Subject: [PATCH] Patch Tool history: refuse a bad name with Polygonal Lasso, give the step its icon historyName is validated before polygonal picks the step name, and the History panel shows the selection icon for a Patch Tool step. --- .../retouch_cmds/patch_history_names_tests.rs | 2 ++ crates/engine/src/cmd/selection_cmds.rs | 14 +++++----- crates/ui-egui/src/panels.rs | 2 ++ crates/ui-egui/src/panels/history.rs | 27 ++++++++++++------- .../src/patch_tool_history_names_tests.rs | 7 +++++ 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs b/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs index fae53cc0e5..6172d5c376 100644 --- a/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs +++ b/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs @@ -53,6 +53,8 @@ fn a_hostile_history_name_is_refused_without_a_step() { let steps = s.active().unwrap().history.past_len(); for name in [json!(""), json!(" "), json!("x".repeat(65)), json!("a\nb"), json!(7), json!(["Patch Tool"])] { assert!(s.execute("select.lasso", json!({"points": TRIANGLE, "historyName": name})).is_err(), "{name}"); + let polygonal = json!({"points": TRIANGLE, "polygonal": true, "historyName": name}); + assert!(s.execute("select.lasso", polygonal).is_err(), "polygonal {name}"); } assert_eq!(s.active().unwrap().history.past_len(), steps); } diff --git a/crates/engine/src/cmd/selection_cmds.rs b/crates/engine/src/cmd/selection_cmds.rs index b74a9d7f9f..90a1c14d88 100644 --- a/crates/engine/src/cmd/selection_cmds.rs +++ b/crates/engine/src/cmd/selection_cmds.rs @@ -624,15 +624,13 @@ fn lasso(s: &mut Session, p: &Value) -> Result { // The History step is named after the tool: the Polygonal Lasso sends `polygonal` (Photoshop). // The Patch and Content-Aware Move tools draw with this command and send their own name as // `historyName`, so the plain Lasso tool keeps "Lasso". - let step = if b(p, "polygonal", false) { - "Polygonal Lasso" - } else { - match p.get("historyName") { - None | Some(Value::Null) => "Lasso", - Some(Value::String(n)) if !n.trim().is_empty() && n.chars().count() <= 64 && !n.chars().any(char::is_control) => n.trim(), - Some(_) => return Err(EngineError::BadParams { cmd: "select.lasso".into(), msg: "historyName must be a short text".into() }), - } + // A bad name is refused even when `polygonal` picks the step's name. + let named = match p.get("historyName") { + None | Some(Value::Null) => None, + Some(Value::String(n)) if !n.trim().is_empty() && n.chars().count() <= 64 && !n.chars().any(char::is_control) => Some(n.trim()), + Some(_) => return Err(EngineError::BadParams { cmd: "select.lasso".into(), msg: "historyName must be a short text".into() }), }; + let step = if b(p, "polygonal", false) { "Polygonal Lasso" } else { named.unwrap_or("Lasso") }; polygon_selection(s, "select.lasso", step, &pts, p) } diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 0d40e2280b..c4a8601769 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -80,6 +80,8 @@ use history::history; pub(crate) use history::select_snapshot; pub(crate) use history::selected_snapshot; #[cfg(test)] +pub(crate) use history::step_icon as history_step_icon; +#[cfg(test)] use info::info_panel; pub(crate) use info::{SamplerReadouts, sampler_readouts}; #[cfg(test)] diff --git a/crates/ui-egui/src/panels/history.rs b/crates/ui-egui/src/panels/history.rs index 38d3797014..1a366876f3 100644 --- a/crates/ui-egui/src/panels/history.rs +++ b/crates/ui-egui/src/panels/history.rs @@ -62,16 +62,7 @@ pub(super) fn history(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } else if resp.hovered() { ui.painter().rect_filled(rect, 0.0, t.hover.gamma_multiply(0.5)); } - let icon = match e.as_str() { - s if s.contains("Brush") || s.contains("Eraser") => "brush", - // The Layers panel's controls (layer.setProps). - "Opacity Change" | "Fill Opacity Change" | "Blending Change" => "layers", - s if s.contains("Layer") => "layers", - s if s.contains("Select") || s.contains("Marquee") || s.contains("Deselect") || s.contains("Lasso") => "square-dashed", - s if s.contains("Fill") => "paint-bucket", - "Open" => "image", - _ => "sliders-horizontal", - }; + let icon = step_icon(&e); let color = if is_redo { t.text_faint } else { t.text }; icons::paint( ui, @@ -197,6 +188,22 @@ pub(super) fn history(app: &mut PhotocraftApp, ui: &mut egui::Ui) { /// The History panel's source column at the left of a state or snapshot row: the History Brush /// icon on the source; a click makes the row the source (`history.setSource`). It sits above the /// row, so the click doesn't also step to the state or snapshot. +/// The icon of a History step, from its name. +pub(crate) fn step_icon(step: &str) -> &'static str { + match step { + s if s.contains("Brush") || s.contains("Eraser") => "brush", + // The Layers panel's controls (layer.setProps). + "Opacity Change" | "Fill Opacity Change" | "Blending Change" => "layers", + s if s.contains("Layer") => "layers", + s if s.contains("Select") || s.contains("Marquee") || s.contains("Deselect") || s.contains("Lasso") => "square-dashed", + // The selections the Patch tool draws (select.lasso's historyName). + "Patch Tool" => "square-dashed", + s if s.contains("Fill") => "paint-bucket", + "Open" => "image", + _ => "sliders-horizontal", + } +} + fn history_source_column(ui: &mut egui::Ui, row: Rect, salt: egui::Id, is_source: bool) -> bool { let t = Tokens::get(ui.ctx()); let cell = Rect::from_min_size(row.min, vec2(24.0, row.height())); diff --git a/crates/ui-egui/src/patch_tool_history_names_tests.rs b/crates/ui-egui/src/patch_tool_history_names_tests.rs index de9054fef1..ef8fec47b5 100644 --- a/crates/ui-egui/src/patch_tool_history_names_tests.rs +++ b/crates/ui-egui/src/patch_tool_history_names_tests.rs @@ -31,3 +31,10 @@ fn the_patch_tool_lasso_is_named_for_the_tool() { assert_eq!(drag_lasso(&mut app_with(Tool::Patch)).as_deref(), Some("Patch Tool")); assert_eq!(drag_lasso(&mut app_with(Tool::Lasso)).as_deref(), Some("Lasso")); } + +/// A Patch tool lasso keeps the selection icon in the History panel. +#[test] +fn the_patch_tool_step_has_the_selection_icon() { + assert_eq!(crate::panels::history_step_icon("Patch Tool"), crate::panels::history_step_icon("Lasso")); + assert_eq!(crate::panels::history_step_icon("Patch Tool"), "square-dashed"); +}