From 974c32ddc693b4c5e71838e8a02efece9942c032 Mon Sep 17 00:00:00 2001 From: SBaksa Date: Sun, 8 Nov 2026 13:09:17 +1100 Subject: [PATCH 1/5] Patch: History names as the tool's (#12117) select.lasso takes an optional historyName; the Patch tool sends "Patch Tool" so its lasso is that step (the Lasso tool keeps "Lasso"). paint.patch records "Patch Selection" in every mode; the content-aware job keeps its progress text. Tests: patch_history_names_tests (engine) and patch_tool_history_names_tests (ui-egui). --- crates/engine/src/cmd/retouch_cmds.rs | 3 + crates/engine/src/cmd/retouch_cmds/patch.rs | 10 ++-- .../retouch_cmds/patch_history_names_tests.rs | 58 +++++++++++++++++++ crates/engine/src/cmd/retouch_cmds/tests.rs | 2 +- crates/engine/src/cmd/selection_cmds.rs | 14 ++++- crates/ui-egui/src/canvas/gesture.rs | 7 ++- crates/ui-egui/src/lib.rs | 2 + .../src/patch_tool_history_names_tests.rs | 33 +++++++++++ 8 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs create mode 100644 crates/ui-egui/src/patch_tool_history_names_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds.rs b/crates/engine/src/cmd/retouch_cmds.rs index 0746ca7440c..3cba7c43182 100644 --- a/crates/engine/src/cmd/retouch_cmds.rs +++ b/crates/engine/src/cmd/retouch_cmds.rs @@ -397,3 +397,6 @@ pub fn specs() -> Vec { #[cfg(test)] mod tests; + +#[cfg(test)] +mod patch_history_names_tests; diff --git a/crates/engine/src/cmd/retouch_cmds/patch.rs b/crates/engine/src/cmd/retouch_cmds/patch.rs index 1cfcd3bfca4..38655075fdc 100644 --- a/crates/engine/src/cmd/retouch_cmds/patch.rs +++ b/crates/engine/src/cmd/retouch_cmds/patch.rs @@ -23,6 +23,8 @@ use super::{ }; const CMD: &str = "paint.patch"; +/// The History step of applying a patch, in every mode. +const HISTORY_NAME: &str = "Patch Selection"; /// Largest patch, in pixels of the selection's bounding box. The solve holds the two regions, the /// result and per-channel float planes of it (on the order of 150 bytes per pixel with four @@ -151,7 +153,6 @@ struct Plan { /// Shift of the repaired area from the selection, and of the texture from the repaired area. dst_shift: (i32, i32), src_shift: (i32, i32), - destination: bool, offset: (i32, i32), } @@ -185,7 +186,7 @@ fn plan(s: &Session, p: &Value) -> Result { PatchMode::Source => ((0, 0), (dx, dy)), PatchMode::Destination => ((dx, dy), (-dx, -dy)), }; - Ok(Plan { id, canvas, area, dst_shift, src_shift, destination: mode == PatchMode::Destination, offset: (dx, dy) }) + Ok(Plan { id, canvas, area, dst_shift, src_shift, offset: (dx, dy) }) } /// Heal `surf` at the selection (shifted by `dst_shift`) with texture read `src_shift` away, the @@ -216,7 +217,7 @@ pub(super) fn patch(s: &mut Session, p: &Value) -> Result { return patch_content_aware(s, p); } let plan = plan(s, p)?; - let label = if plan.destination { "Patch (Destination)" } else { "Patch" }; + let label = HISTORY_NAME; let dmg = run_stroke(s, label, plan.id, p, |pre, surf, _, lock| { let sel = pre.selection.as_ref().ok_or_else(|| bad(CMD, "select the area to patch first"))?; Ok(patch_surface(surf, sel, &plan, lock, 1)) @@ -263,6 +264,7 @@ fn level(p: &Value, k: &str, default: u8, lo: u8, hi: u8) -> Result { /// docs), as a background job. fn patch_content_aware(s: &mut Session, p: &Value) -> Result { use super::content_aware_move::{Target, land, mask, read, window}; + // The job's progress text; its History step is `HISTORY_NAME`. const LABEL: &str = "Patch (Content-Aware)"; let plan = plan(s, p)?; let structure = level(p, "structure", 4, 1, 7)?; @@ -294,7 +296,7 @@ fn patch_content_aware(s: &mut Session, p: &Value) -> Result { } }, move |s, (surf, damage)| { - s.edit(LABEL, |doc, _| { + s.edit(HISTORY_NAME, |doc, _| { *crate::channel_cmds::target_surface(doc, target.id, &p)?.0 = surf; Ok(()) })?; 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 new file mode 100644 index 00000000000..fae53cc0e5f --- /dev/null +++ b/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs @@ -0,0 +1,58 @@ +//! History step names of the Patch Tool (#12117): "Patch Tool" for the lasso it draws with and +//! "Patch Selection" for applying a patch in every mode; the plain Lasso tool keeps "Lasso". + +use super::*; + +fn session() -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 128, "height": 64, "depth": 8, "mode": "rgb"})).unwrap(); + s +} + +fn last_step(s: &Session) -> Option { + s.active().unwrap().history.undo_label().map(str::to_string) +} + +#[test] +fn applying_a_patch_is_one_step_named_patch_selection_in_every_mode() { + let modes = [ + json!({"offset": [30, 0]}), + json!({"offset": [30, 0], "mode": "source"}), + json!({"offset": [30, 0], "mode": "destination"}), + json!({"offset": [30, 0], "contentAware": true}), + json!({"offset": [30, 0], "mode": "destination", "contentAware": true}), + ]; + for p in modes { + let mut s = session(); + s.execute("select.rect", json!({"x": 16, "y": 22, "width": 20, "height": 20})).unwrap(); + let steps = s.active().unwrap().history.past_len(); + s.execute("paint.patch", p.clone()).unwrap(); + assert_eq!(s.active().unwrap().history.past_len(), steps + 1, "{p}: one step"); + assert_eq!(last_step(&s).as_deref(), Some("Patch Selection"), "{p}"); + } +} + +const TRIANGLE: [[i32; 2]; 3] = [[16, 22], [36, 22], [16, 42]]; + +#[test] +fn the_lasso_is_named_for_the_tool_that_drew_it() { + let mut s = session(); + s.execute("select.lasso", json!({"points": TRIANGLE})).unwrap(); + assert_eq!(last_step(&s).as_deref(), Some("Lasso"), "the Lasso tool sends no name"); + for mode in ["replace", "add", "subtract", "intersect"] { + s.execute("select.lasso", json!({"points": TRIANGLE, "mode": mode, "historyName": "Patch Tool"})).unwrap(); + assert_eq!(last_step(&s).as_deref(), Some("Patch Tool"), "{mode}"); + } + s.execute("select.lasso", json!({"points": TRIANGLE, "polygonal": true, "historyName": "Patch Tool"})).unwrap(); + assert_eq!(last_step(&s).as_deref(), Some("Polygonal Lasso"), "the Polygonal Lasso keeps its own name"); +} + +#[test] +fn a_hostile_history_name_is_refused_without_a_step() { + let mut s = session(); + 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}"); + } + assert_eq!(s.active().unwrap().history.past_len(), steps); +} diff --git a/crates/engine/src/cmd/retouch_cmds/tests.rs b/crates/engine/src/cmd/retouch_cmds/tests.rs index 25ebcc8a971..636d3c1ce7e 100644 --- a/crates/engine/src/cmd/retouch_cmds/tests.rs +++ b/crates/engine/src/cmd/retouch_cmds/tests.rs @@ -1022,7 +1022,7 @@ fn patch_content_aware_copies_the_dragged_to_content_into_the_selection() { let (got, want) = (rgba(&s, x, y), texture(x, y)); assert!((got[0] - want[0]).abs() <= tol(depth), "depth {depth}: untouched {x},{y}: {got:?}"); } - assert_eq!(s.active().unwrap().history.undo_label(), Some("Patch (Content-Aware)")); + assert_eq!(s.active().unwrap().history.undo_label(), Some("Patch Selection")); s.execute("edit.undo", json!({})).unwrap(); assert_eq!(rgba(&s, 44, 24)[1], 0.0, "depth {depth}: undo brings the blemish back"); } diff --git a/crates/engine/src/cmd/selection_cmds.rs b/crates/engine/src/cmd/selection_cmds.rs index 13737e70bd4..b74a9d7f9f7 100644 --- a/crates/engine/src/cmd/selection_cmds.rs +++ b/crates/engine/src/cmd/selection_cmds.rs @@ -622,7 +622,17 @@ fn lasso(s: &mut Session, p: &Value) -> Result { return Err(EngineError::BadParams { cmd: "select.lasso".into(), msg: "needs at least 3 points".into() }); } // The History step is named after the tool: the Polygonal Lasso sends `polygonal` (Photoshop). - let step = if b(p, "polygonal", false) { "Polygonal Lasso" } else { "Lasso" }; + // 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() }), + } + }; polygon_selection(s, "select.lasso", step, &pts, p) } @@ -756,7 +766,7 @@ pub fn specs() -> Vec { "select.lasso", "Lasso", [], - r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false}"##, + r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false,"historyName"?:text (1..64 characters, no control characters; the History step name when a tool other than the Lasso draws it, e.g. "Patch Tool"; default "Lasso")}"##, has_doc, lasso ), diff --git a/crates/ui-egui/src/canvas/gesture.rs b/crates/ui-egui/src/canvas/gesture.rs index b67aec4bebd..60af838375e 100644 --- a/crates/ui-egui/src/canvas/gesture.rs +++ b/crates/ui-egui/src/canvas/gesture.rs @@ -144,7 +144,12 @@ fn finish(app: &mut PhotocraftApp, mut d: Drag, click: Option) { let o = &app.ui.tool_options; // The Patch and Content-Aware Move tools have no Feather in their options bar. let feather = if d.tool == Tool::Lasso { o.feather } else { 0.0 }; - let made = app.run("select.lasso", json!({"points": pts, "mode": mode, "antiAlias": o.anti_alias, "feather": feather})); + let mut params = json!({"points": pts, "mode": mode, "antiAlias": o.anti_alias, "feather": feather}); + // The Patch tool's lasso is a step of that tool in History; the Lasso tool keeps "Lasso". + if d.tool == Tool::Patch { + params["historyName"] = json!("Patch Tool"); + } + let made = app.run("select.lasso", params); // The lasso only outlines the patch; say that it is dragged next (#1715). if made.is_ok() && d.tool != Tool::Lasso { crate::retouch_ui::patch_hint(app); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 7d5d2a90e86..3ee1d27bbeb 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -979,6 +979,8 @@ mod status_bar_tests; #[cfg(test)] mod stroke_timing_tests; +#[cfg(test)] +mod patch_tool_history_names_tests; #[cfg(test)] mod polygon_lasso_step_snap_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/patch_tool_history_names_tests.rs b/crates/ui-egui/src/patch_tool_history_names_tests.rs new file mode 100644 index 00000000000..de9054fef1b --- /dev/null +++ b/crates/ui-egui/src/patch_tool_history_names_tests.rs @@ -0,0 +1,33 @@ +//! The Patch tool's lasso is a History step named "Patch Tool" (#12117); the Lasso tool keeps "Lasso". + +use egui::Modifiers; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +fn app_with(tool: Tool) -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600, "background": "transparent"})).unwrap(); + app.sync_views(); + app.ui.tool = tool; + app +} + +/// Drag a triangle with the active tool and return the last History step. +fn drag_lasso(app: &mut PhotocraftApp) -> Option { + tool_event(app, ToolEvent::Down { x: 100.0, y: 100.0, pressure: 1.0 }, Modifiers::NONE); + for (x, y) in [(200.0, 100.0), (300.0, 100.0), (300.0, 300.0)] { + tool_event(app, ToolEvent::Move { x, y, pressure: 1.0 }, Modifiers::NONE); + } + tool_event(app, ToolEvent::Up { x: 200.0, y: 300.0 }, Modifiers::NONE); + assert!(app.session.active().unwrap().doc.selection.is_some()); + app.session.active().unwrap().history.entries().last().cloned() +} + +#[test] +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")); +} From 60d0895c270a9ca85111fbfa3501ab9cc5dcb708 Mon Sep 17 00:00:00 2001 From: SBaksa Date: Sun, 8 Nov 2026 14:32:37 +1100 Subject: [PATCH 2/5] 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 fae53cc0e5f..6172d5c3764 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 b74a9d7f9f7..90a1c14d88f 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 0d40e2280b6..c4a86017697 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 38d37970145..1a366876f35 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 de9054fef1b..ef8fec47b5b 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"); +} From be7ebc078a87eedc8fdc2cb431dadb248062e6b6 Mon Sep 17 00:00:00 2001 From: SBaksa <18648812+SBaksa@users.noreply.github.com> Date: Sun, 8 Nov 2026 17:36:30 +1100 Subject: [PATCH 3/5] Lasso: refuse a history name that shows nothing or hides formatting A historyName of zero-width, filler or BOM characters showed an empty History row, and a bidi control or line separator could make a row read differently from its name. A history name now has no control or line-break character anywhere, loses white space and ZWNJ/ZWJ at its ends, and is then held to the plug-in menu-label rule, now shared as photocraft_plugins::manifest::printable_name (1-64 characters with a visible one, no hidden format characters; plug-in names also refuse U+2028/U+2029). --- .../retouch_cmds/patch_history_names_tests.rs | 33 ++++++++++++++++++- crates/engine/src/cmd/selection_cmds.rs | 20 +++++++++-- crates/plugins/src/manifest.rs | 12 +++++-- 3 files changed, 58 insertions(+), 7 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 6172d5c3764..d72958fc3a5 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 @@ -51,10 +51,41 @@ fn the_lasso_is_named_for_the_tool_that_drew_it() { fn a_hostile_history_name_is_refused_without_a_step() { let mut s = session(); 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"])] { + let invisible = ["\u{200B}", " \u{200B}\u{FEFF} ", "\u{3164}", "\u{FE0F}", "\u{E0020}", "\u{00AD}"]; + let hidden = ["Patch\u{202E}looT", "\u{FEFF}Patch Tool", "Patch Tool\u{200B}", "\u{2066}Patch", "Patch\u{2028}Tool", "a\u{2029}b"]; + let ends = ["Patch Tool\n", "\r\nPatch Tool", "\tPatch", "\u{0085}Patch", "Patch\u{2028}"]; + let others = [json!(""), json!(" "), json!("x".repeat(65)), json!("a\nb"), json!(7), json!(["Patch Tool"])]; + let others = ends.iter().map(|n| json!(n)).chain(others); + for name in invisible.iter().chain(&hidden).map(|n| json!(n)).chain(others) { 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); } + +#[test] +fn a_name_joining_its_letters_with_a_zero_width_joiner_is_kept() { + let mut s = session(); + for name in ["\u{0645}\u{200C}\u{06CC}", "\u{1F469}\u{200D}\u{1F4BB}", "Patch Tool \u{2713}"] { + s.execute("select.lasso", json!({"points": TRIANGLE, "historyName": name})).unwrap(); + assert_eq!(last_step(&s).as_deref(), Some(name)); + } +} + +#[test] +fn spaces_and_joiners_at_the_ends_are_trimmed_and_only_what_is_left_counts() { + let mut s = session(); + let padded = format!("{}{}", " ".repeat(10), "x".repeat(60)); + let joined = format!("Patch Tool{}", "\u{200D}".repeat(60)); + let cases = [ + ("Patch Tool\u{200D}", "Patch Tool"), + (" \u{200C}Patch Tool ", "Patch Tool"), + ("Love \u{2764}\u{FE0F}", "Love \u{2764}\u{FE0F}"), + (joined.as_str(), "Patch Tool"), + ]; + for (name, stored) in cases.iter().copied().chain([(padded.as_str(), &padded[10..])]) { + s.execute("select.lasso", json!({"points": TRIANGLE, "historyName": name})).unwrap(); + assert_eq!(last_step(&s).as_deref(), Some(stored), "{name:?}"); + } +} diff --git a/crates/engine/src/cmd/selection_cmds.rs b/crates/engine/src/cmd/selection_cmds.rs index 90a1c14d88f..ed4b60cc96a 100644 --- a/crates/engine/src/cmd/selection_cmds.rs +++ b/crates/engine/src/cmd/selection_cmds.rs @@ -627,13 +627,27 @@ fn lasso(s: &mut Session, p: &Value) -> Result { // 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() }), + Some(Value::String(n)) if history_name(n).is_some() => history_name(n), + Some(_) => { + let msg = "historyName must be 1-64 characters with a visible one, and no control, line-break or hidden format characters"; + return Err(EngineError::BadParams { cmd: "select.lasso".into(), msg: msg.into() }); + } }; let step = if b(p, "polygonal", false) { "Polygonal Lasso" } else { named.unwrap_or("Lasso") }; polygon_selection(s, "select.lasso", step, &pts, p) } +/// The History step name for `historyName` `n`: refused when it has a control or line-break +/// character anywhere; otherwise without white space or zero-width (non-)joiners at its ends, so a +/// name that looks like "Patch Tool" is "Patch Tool", and then held to the plug-in menu-label rule. +fn history_name(n: &str) -> Option<&str> { + if n.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}')) { + return None; + } + let t = n.trim_matches(|c: char| c.is_whitespace() || matches!(c, '\u{200C}' | '\u{200D}')); + photocraft_plugins::manifest::printable_name(t).then_some(t) +} + /// Selects the polygon `pts` with the lasso tools' `mode`, `antiAlias` and `feather` params, as /// one history step called `label`. pub(crate) fn polygon_selection(s: &mut Session, cmd: &str, label: &str, pts: &[(f32, f32)], p: &Value) -> Result { @@ -764,7 +778,7 @@ pub fn specs() -> Vec { "select.lasso", "Lasso", [], - r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false,"historyName"?:text (1..64 characters, no control characters; the History step name when a tool other than the Lasso draws it, e.g. "Patch Tool"; default "Lasso")}"##, + r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false,"historyName"?:text (1..64 characters with a visible one, no control, line-break or hidden format characters, spaces and joiners at the ends trimmed; the History step name when a tool other than the Lasso draws it, e.g. "Patch Tool"; default "Lasso")}"##, has_doc, lasso ), diff --git a/crates/plugins/src/manifest.rs b/crates/plugins/src/manifest.rs index 133c0fa843c..f8116198fec 100644 --- a/crates/plugins/src/manifest.rs +++ b/crates/plugins/src/manifest.rs @@ -143,9 +143,7 @@ impl Manifest { if !valid_id(&self.id) { return Err(Error::Manifest(format!("invalid id {:?}: use 1-64 characters from A-Z a-z 0-9 . _ -", self.id))); } - let name = self.name.trim(); - let printable = name.chars().all(|c| !c.is_control() && !hidden_format(c)) && name.chars().any(visible); - if !printable || name.chars().count() > 64 { + if !printable_name(self.name.trim()) { return Err(Error::Manifest("`name` must be 1-64 printable characters".into())); } if self.version.len() > 32 || self.description.len() > 1024 || self.author.len() > 128 { @@ -399,6 +397,12 @@ fn hidden_format(c: char) -> bool { !matches!(c, '\u{200C}' | '\u{200D}') && in_ranges(c, FORMAT) } +/// Whether `name` (already trimmed) can be shown as a label: 1-64 characters, at least one of them +/// visible, and no control characters, line or paragraph separators, or hidden format characters. +pub fn printable_name(name: &str) -> bool { + name.chars().count() <= 64 && name.chars().any(visible) && !name.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}') || hidden_format(c)) +} + /// A character that draws something on its own. fn visible(c: char) -> bool { !c.is_whitespace() && !c.is_control() && !in_ranges(c, FORMAT) && !in_ranges(c, BLANK) @@ -631,6 +635,8 @@ mod tests { "\u{3164}\u{FE0F}", " \u{3000} ", "Tone\u{7}", + "Tone\u{2028}Pro", + "Tone\u{2029}Pro", ] { assert!(with_name(bad).is_err(), "{bad:?}"); } From c2f85a590f97f29aac46eb865b56bab58dd13429 Mon Sep 17 00:00:00 2001 From: SBaksa <18648812+SBaksa@users.noreply.github.com> Date: Sun, 8 Nov 2026 19:59:43 +1100 Subject: [PATCH 4/5] Plug-in names: store the name trimmed, count U+2800 and unassigned ignorables as blank A manifest name such as "\nTone" was checked trimmed but shown as given, so a line break reached the menu; padding also got past the 64-character limit. The name is now stored trimmed. The blank Braille pattern and the unassigned default-ignorable ranges no longer count as visible, in plug-in names and History names. Applying a patch no longer takes the selection icon, and the History source column has its doc comment back. --- .../retouch_cmds/patch_history_names_tests.rs | 2 +- crates/plugins/src/manifest.rs | 33 +++++++++++++++---- crates/ui-egui/src/panels/history.rs | 8 +++-- .../src/patch_tool_history_names_tests.rs | 2 ++ 4 files changed, 35 insertions(+), 10 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 d72958fc3a5..b3e87b0d6d6 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 @@ -51,7 +51,7 @@ fn the_lasso_is_named_for_the_tool_that_drew_it() { fn a_hostile_history_name_is_refused_without_a_step() { let mut s = session(); let steps = s.active().unwrap().history.past_len(); - let invisible = ["\u{200B}", " \u{200B}\u{FEFF} ", "\u{3164}", "\u{FE0F}", "\u{E0020}", "\u{00AD}"]; + let invisible = ["\u{200B}", " \u{200B}\u{FEFF} ", "\u{3164}", "\u{FE0F}", "\u{E0020}", "\u{00AD}", "\u{2800}"]; let hidden = ["Patch\u{202E}looT", "\u{FEFF}Patch Tool", "Patch Tool\u{200B}", "\u{2066}Patch", "Patch\u{2028}Tool", "a\u{2029}b"]; let ends = ["Patch Tool\n", "\r\nPatch Tool", "\tPatch", "\u{0085}Patch", "Patch\u{2028}"]; let others = [json!(""), json!(" "), json!("x".repeat(65)), json!("a\nb"), json!(7), json!(["Patch Tool"])]; diff --git a/crates/plugins/src/manifest.rs b/crates/plugins/src/manifest.rs index f8116198fec..1273dfea266 100644 --- a/crates/plugins/src/manifest.rs +++ b/crates/plugins/src/manifest.rs @@ -134,7 +134,9 @@ impl Manifest { return Err(Error::Manifest(format!("manifest is {} bytes (limit {MAX_MANIFEST_BYTES})", bytes.len()))); } let text = std::str::from_utf8(bytes).map_err(|_| Error::Manifest("manifest is not UTF-8".into()))?; - let man: Manifest = serde_json::from_str(text).map_err(|e| Error::Manifest(format!("manifest: {e}")))?; + let mut man: Manifest = serde_json::from_str(text).map_err(|e| Error::Manifest(format!("manifest: {e}")))?; + // The name is shown as stored, so white space and line breaks at its ends are dropped here. + man.name = man.name.trim().to_owned(); man.validate()?; Ok(man) } @@ -143,7 +145,7 @@ impl Manifest { if !valid_id(&self.id) { return Err(Error::Manifest(format!("invalid id {:?}: use 1-64 characters from A-Z a-z 0-9 . _ -", self.id))); } - if !printable_name(self.name.trim()) { + if !printable_name(&self.name) { return Err(Error::Manifest("`name` must be 1-64 printable characters".into())); } if self.version.len() > 32 || self.description.len() > 1024 || self.author.len() > 128 { @@ -372,18 +374,23 @@ const FORMAT: &[(char, char)] = &[ ('\u{E0020}', '\u{E007F}'), ]; -/// Default-ignorable characters outside Cf (fillers, variation selectors): allowed in a name, but they -/// draw nothing on their own. +/// Default-ignorable characters outside Cf (fillers, variation selectors, unassigned ignorables), and +/// the blank Braille pattern U+2800: allowed in a name, but they draw nothing on their own. const BLANK: &[(char, char)] = &[ ('\u{34F}', '\u{34F}'), ('\u{115F}', '\u{1160}'), ('\u{17B4}', '\u{17B5}'), ('\u{180B}', '\u{180D}'), ('\u{180F}', '\u{180F}'), + ('\u{2065}', '\u{2065}'), + ('\u{2800}', '\u{2800}'), ('\u{3164}', '\u{3164}'), ('\u{FE00}', '\u{FE0F}'), ('\u{FFA0}', '\u{FFA0}'), - ('\u{E0100}', '\u{E01EF}'), + ('\u{FFF0}', '\u{FFF8}'), + ('\u{E0000}', '\u{E0000}'), + ('\u{E0002}', '\u{E001F}'), + ('\u{E0080}', '\u{E0FFF}'), ]; fn in_ranges(c: char, ranges: &[(char, char)]) -> bool { @@ -400,7 +407,9 @@ fn hidden_format(c: char) -> bool { /// Whether `name` (already trimmed) can be shown as a label: 1-64 characters, at least one of them /// visible, and no control characters, line or paragraph separators, or hidden format characters. pub fn printable_name(name: &str) -> bool { - name.chars().count() <= 64 && name.chars().any(visible) && !name.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}') || hidden_format(c)) + name.chars().nth(64).is_none() + && name.chars().any(visible) + && !name.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}') || hidden_format(c)) } /// A character that draws something on its own. @@ -637,6 +646,12 @@ mod tests { "Tone\u{7}", "Tone\u{2028}Pro", "Tone\u{2029}Pro", + "\u{2800}", + " \u{2800}\u{2800} ", + "\u{2065}", + "\u{FFF0}", + "\u{E0000}\u{E0002}", + "\u{E0080}\u{E0FFF}", ] { assert!(with_name(bad).is_err(), "{bad:?}"); } @@ -644,6 +659,12 @@ mod tests { for good in ["Tone…", "Kontrast ±", "می\u{200C}خواهم", "\u{1F469}\u{200D}\u{1F4BB} Code", "\u{2764}\u{FE0F} Love", "色调"] { assert_eq!(with_name(good).map(|m| m.name).ok().as_deref(), Some(good)); } + // White space and line breaks at the ends are dropped from the stored name, so the menu never + // shows them, and padding does not count towards the limit. + for (padded, stored) in [("\nTone", "Tone"), ("Tone\r\n", "Tone"), ("\u{2028}Tone ", "Tone"), (" Tone… ", "Tone…")] { + assert_eq!(with_name(padded).map(|m| m.name).ok().as_deref(), Some(stored), "{padded:?}"); + } + assert_eq!(with_name(&format!("{}{}", "x".repeat(64), " ".repeat(1000))).map(|m| m.name.len()).ok(), Some(64)); // The documented limit counts characters, not bytes. assert!(with_name(&"é".repeat(64)).is_ok()); assert!(with_name(&"é".repeat(65)).is_err()); diff --git a/crates/ui-egui/src/panels/history.rs b/crates/ui-egui/src/panels/history.rs index 1a366876f35..e75dbbb5b90 100644 --- a/crates/ui-egui/src/panels/history.rs +++ b/crates/ui-egui/src/panels/history.rs @@ -185,13 +185,12 @@ 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", + // Applying a patch edits pixels; only the Patch tool's lasso is a selection step. + "Patch Selection" => "sliders-horizontal", // The Layers panel's controls (layer.setProps). "Opacity Change" | "Fill Opacity Change" | "Blending Change" => "layers", s if s.contains("Layer") => "layers", @@ -204,6 +203,9 @@ pub(crate) fn step_icon(step: &str) -> &'static str { } } +/// 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. 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 ef8fec47b5b..d0dc3e771d5 100644 --- a/crates/ui-egui/src/patch_tool_history_names_tests.rs +++ b/crates/ui-egui/src/patch_tool_history_names_tests.rs @@ -37,4 +37,6 @@ fn the_patch_tool_lasso_is_named_for_the_tool() { 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"); + // Applying the patch edits pixels, so it does not take the selection icon from "Selection". + assert_ne!(crate::panels::history_step_icon("Patch Selection"), "square-dashed"); } From 28d2d9095dbbce480b09cff5cd37165993ba128d Mon Sep 17 00:00:00 2001 From: SBaksa <18648812+SBaksa@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:58:21 +1100 Subject: [PATCH 5/5] History and plug-in names: trim the fillers and blank padding at the ends too trim_name drops white space, ZWNJ/ZWJ and the blank characters (Braille blank, Hangul fillers, invisible operators, tag and other default-ignorable blanks) from both ends. A variation or Mongolian free variation selector or CGJ that belongs to a kept character stays, and so do Hangul filler jamo that complete a syllable. History names use the same trim as plug-in names. --- .../retouch_cmds/patch_history_names_tests.rs | 9 ++ crates/engine/src/cmd/selection_cmds.rs | 9 +- crates/plugins/src/manifest.rs | 101 +++++++++++++++++- docs/plugins.md | 3 + 4 files changed, 115 insertions(+), 7 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 b3e87b0d6d6..2fcee6e1d73 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 @@ -83,6 +83,15 @@ fn spaces_and_joiners_at_the_ends_are_trimmed_and_only_what_is_left_counts() { (" \u{200C}Patch Tool ", "Patch Tool"), ("Love \u{2764}\u{FE0F}", "Love \u{2764}\u{FE0F}"), (joined.as_str(), "Patch Tool"), + ("Patch Tool\u{2800}", "Patch Tool"), + ("\u{3164}\u{2800}Patch Tool\u{FFA0} \u{115F}", "Patch Tool"), + ("Patch Tool\u{2065}\u{FFF0}", "Patch Tool"), + ("\u{17B4}Patch Tool", "Patch Tool"), + ("Patch Tool \u{FE0F}", "Patch Tool"), + ("\u{FE0F}Patch Tool", "Patch Tool"), + ("Patch \u{2764}\u{FE0F}\u{2800}", "Patch \u{2764}\u{FE0F}"), + ("Patch \u{1100}\u{1160}", "Patch \u{1100}\u{1160}"), + ("\u{115F}\u{1161} Patch", "\u{115F}\u{1161} Patch"), ]; for (name, stored) in cases.iter().copied().chain([(padded.as_str(), &padded[10..])]) { s.execute("select.lasso", json!({"points": TRIANGLE, "historyName": name})).unwrap(); diff --git a/crates/engine/src/cmd/selection_cmds.rs b/crates/engine/src/cmd/selection_cmds.rs index ed4b60cc96a..798b4f03a0e 100644 --- a/crates/engine/src/cmd/selection_cmds.rs +++ b/crates/engine/src/cmd/selection_cmds.rs @@ -638,13 +638,14 @@ fn lasso(s: &mut Session, p: &Value) -> Result { } /// The History step name for `historyName` `n`: refused when it has a control or line-break -/// character anywhere; otherwise without white space or zero-width (non-)joiners at its ends, so a -/// name that looks like "Patch Tool" is "Patch Tool", and then held to the plug-in menu-label rule. +/// character anywhere; otherwise without its invisible end padding (see +/// [`photocraft_plugins::manifest::trim_name`]), so a name that looks like "Patch Tool" is "Patch Tool", +/// and then held to the plug-in menu-label rule. fn history_name(n: &str) -> Option<&str> { if n.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}')) { return None; } - let t = n.trim_matches(|c: char| c.is_whitespace() || matches!(c, '\u{200C}' | '\u{200D}')); + let t = photocraft_plugins::manifest::trim_name(n); photocraft_plugins::manifest::printable_name(t).then_some(t) } @@ -778,7 +779,7 @@ pub fn specs() -> Vec { "select.lasso", "Lasso", [], - r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false,"historyName"?:text (1..64 characters with a visible one, no control, line-break or hidden format characters, spaces and joiners at the ends trimmed; the History step name when a tool other than the Lasso draws it, e.g. "Patch Tool"; default "Lasso")}"##, + r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false,"historyName"?:text (1..64 characters with a visible one, no control, line-break or hidden format characters, invisible padding at the ends (spaces, joiners, fillers, blank Braille and other default-ignorable blanks, and selectors cut off by them) trimmed; the History step name when a tool other than the Lasso draws it, e.g. "Patch Tool"; default "Lasso")}"##, has_doc, lasso ), diff --git a/crates/plugins/src/manifest.rs b/crates/plugins/src/manifest.rs index 1273dfea266..494a4cb6a96 100644 --- a/crates/plugins/src/manifest.rs +++ b/crates/plugins/src/manifest.rs @@ -135,8 +135,9 @@ impl Manifest { } let text = std::str::from_utf8(bytes).map_err(|_| Error::Manifest("manifest is not UTF-8".into()))?; let mut man: Manifest = serde_json::from_str(text).map_err(|e| Error::Manifest(format!("manifest: {e}")))?; - // The name is shown as stored, so white space and line breaks at its ends are dropped here. - man.name = man.name.trim().to_owned(); + // The name is shown as stored, so the invisible padding at its ends (white space, line breaks, + // joiners, fillers) is dropped here. + man.name = trim_name(&man.name).to_owned(); man.validate()?; Ok(man) } @@ -412,6 +413,77 @@ pub fn printable_name(name: &str) -> bool { && !name.chars().any(|c| c.is_control() || matches!(c, '\u{2028}' | '\u{2029}') || hidden_format(c)) } +/// `name` without what pads its ends invisibly: white space, the zero-width (non-)joiners and the +/// characters that draw nothing on their own (fillers, blank Braille, unassigned ignorables, stray +/// selectors), so a name that looks like "Tone" is "Tone". What belongs to a character the name +/// keeps stays: a variation selector after it (the emoji in "Love ❤️"), and a Hangul filler that +/// is part of a syllable block (U+1160 after a leading consonant, U+115F before a vowel). +pub fn trim_name(name: &str) -> &str { + let pad = |c: char| c.is_whitespace() || matches!(c, '\u{200C}' | '\u{200D}') || in_ranges(c, BLANK); + let mut start = name.len(); + let mut chars = name.char_indices().peekable(); + while let Some((i, c)) = chars.next() { + // The choseong filler opens a syllable before a vowel, and before the jungseong filler U+1160 + // when a final consonant follows (U+115F U+1160 + a final consonant is how a lone final + // consonant is written; U+115F U+1160 alone draws nothing). + let opens_syllable = c == '\u{115F}' + && chars.peek().is_some_and(|&(j, n)| { + vowel_jamo(n) || (n == '\u{1160}' && name.get(j + n.len_utf8()..).and_then(|r| r.chars().next()).is_some_and(trailing_jamo)) + }); + if !pad(c) || opens_syllable { + start = i; + break; + } + } + let s = name.get(start..).unwrap_or_default(); + let mut end = s.len(); + for (i, c) in s.char_indices().rev() { + if !pad(c) { + break; + } + end = i; + } + // Take back the mark that belongs to the last character kept: one per character, so a run of + // selectors after it is still padding. + let mut prev = s.get(..end).and_then(|h| h.chars().next_back()); + for c in s.get(end..).unwrap_or_default().chars() { + let belongs = match prev { + Some(p) => attaches(c) || (c == '\u{1160}' && leading_jamo(p)), + None => false, + }; + if !belongs { + break; + } + end += c.len_utf8(); + prev = if attaches(c) { None } else { Some(c) }; + } + s.get(..end).unwrap_or_default() +} + +/// The marks among [`BLANK`] that modify the character before them: the combining grapheme joiner, +/// the Khmer inherent vowels, the Mongolian free variation selectors and the variation selectors. +fn attaches(c: char) -> bool { + matches!( + c, + '\u{34F}' | '\u{17B4}' | '\u{17B5}' | '\u{180B}'..='\u{180D}' | '\u{180F}' | '\u{FE00}'..='\u{FE0F}' | '\u{E0100}'..='\u{E01EF}' + ) +} + +/// A conjoining Hangul leading consonant (choseong), not the filler U+115F. +fn leading_jamo(c: char) -> bool { + matches!(c, '\u{1100}'..='\u{115E}' | '\u{A960}'..='\u{A97C}') +} + +/// A conjoining Hangul final consonant (jongseong). +fn trailing_jamo(c: char) -> bool { + matches!(c, '\u{11A8}'..='\u{11FF}' | '\u{D7CB}'..='\u{D7FB}') +} + +/// A conjoining Hangul vowel (jungseong) other than the vowel filler U+1160. +fn vowel_jamo(c: char) -> bool { + matches!(c, '\u{1161}'..='\u{11A7}' | '\u{D7B0}'..='\u{D7C6}') +} + /// A character that draws something on its own. fn visible(c: char) -> bool { !c.is_whitespace() && !c.is_control() && !in_ranges(c, FORMAT) && !in_ranges(c, BLANK) @@ -661,7 +733,30 @@ mod tests { } // White space and line breaks at the ends are dropped from the stored name, so the menu never // shows them, and padding does not count towards the limit. - for (padded, stored) in [("\nTone", "Tone"), ("Tone\r\n", "Tone"), ("\u{2028}Tone ", "Tone"), (" Tone… ", "Tone…")] { + for (padded, stored) in [ + ("\nTone", "Tone"), + ("Tone\r\n", "Tone"), + ("\u{2028}Tone ", "Tone"), + (" Tone… ", "Tone…"), + ("Tone\u{2800}", "Tone"), + ("\u{3164}\u{2800}Tone\u{FFA0}", "Tone"), + ("\u{2764}\u{FE0F} Love\u{2800}", "\u{2764}\u{FE0F} Love"), + ("Tone\u{2065}\u{FFF0}", "Tone"), + ("\u{17B4}Tone", "Tone"), + // A selector right after the last kept character belongs to it and stays; one cut off by padding goes. + ("Love \u{2764}\u{FE0F}\u{2800}", "Love \u{2764}\u{FE0F}"), + ("Tone \u{FE0F}", "Tone"), + ("\u{FE0F}Tone", "Tone"), + ("Love \u{2764}\u{FE0F}\u{FE0F}\u{FE0F}", "Love \u{2764}\u{FE0F}"), + // Hangul filler jamo that complete a syllable are part of the name; the two fillers alone draw nothing. + ("\u{115F}\u{1160}Tone", "Tone"), + ("Tone \u{115F}\u{1160}", "Tone"), + ("Tone \u{1100}\u{1160}", "Tone \u{1100}\u{1160}"), + ("\u{115F}\u{1161} Tone", "\u{115F}\u{1161} Tone"), + ("\u{115F}\u{1160}\u{11A8} Tone", "\u{115F}\u{1160}\u{11A8} Tone"), + // Khmer inherent vowels belong to the consonant before them. + ("Tone \u{1780}\u{17B5}", "Tone \u{1780}\u{17B5}"), + ] { assert_eq!(with_name(padded).map(|m| m.name).ok().as_deref(), Some(stored), "{padded:?}"); } assert_eq!(with_name(&format!("{}{}", "x".repeat(64), " ".repeat(1000))).map(|m| m.name.len()).ok(), Some(64)); diff --git a/docs/plugins.md b/docs/plugins.md index 4f582ae9e44..bb2859cef8f 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -100,6 +100,9 @@ exports. All integers are `i32` unless noted; pointers are offsets into the modu - `name`: the menu label (1–64 printable characters). Any script works, but control characters and Unicode format characters (bidi overrides and marks, zero-width spaces, soft hyphens) are rejected, except the zero-width joiner and non-joiner, and at least one character must be visible. + Invisible padding at the ends (white space, joiners, Hangul fillers, blank Braille and other + default-ignorable blanks, and variation selectors cut off by them) is removed before these checks, + so it does not count towards the limit; marks that belong to a kept character stay. `kind`: `"filter"` (the only kind in v1). - `params`: in dialog order. Names are `[A-Za-z0-9_]`, not starting with `_`, not `id`/`layer`. The host validates the user's values before calling: missing values take the default, numbers are