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.
This commit is contained in:
SBaksa committed 2026-11-08 14:32:37 +11:00
1 parent 974c32ddc6
commit 60d0895c27
5 files changed
+34 -18

No files matched your search

@@ -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);
}
+6 -8
View File
@@ -624,15 +624,13 @@ fn lasso(s: &mut Session, p: &Value) -> Result<Value> {
// 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)
}
+2
View File
@@ -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)]
+17 -10
View File
@@ -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()));
@@ -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");
}