Merge pull request #12255 from SBaksa/patch-history-names

Patch: History names as the tool's (fixes #12117)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-08 15:25:52 +01:00
commit 848fa306f5
12 files changed
+338 -25

No files matched your search

+3
View File
@@ -397,3 +397,6 @@ pub fn specs() -> Vec<CommandSpec> {
#[cfg(test)]
mod tests;
#[cfg(test)]
mod patch_history_names_tests;
+6 -4
View File
@@ -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<Plan> {
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<Value> {
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<u8> {
/// docs), as a background job.
fn patch_content_aware(s: &mut Session, p: &Value) -> Result<Value> {
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<Value> {
}
},
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(())
})?;
@@ -0,0 +1,100 @@
//! 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<String> {
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();
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"])];
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"),
("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();
assert_eq!(last_step(&s).as_deref(), Some(stored), "{name:?}");
}
}
+1 -1
View File
@@ -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");
}
+25 -2
View File
@@ -622,10 +622,33 @@ fn lasso(s: &mut Session, p: &Value) -> Result<Value> {
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".
// 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 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 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 = photocraft_plugins::manifest::trim_name(n);
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<Value> {
@@ -756,7 +779,7 @@ pub fn specs() -> Vec<CommandSpec> {
"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 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
),
+129 -7
View File
@@ -134,7 +134,10 @@ 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 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)
}
@@ -143,9 +146,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) {
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 {
@@ -374,18 +375,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 {
@@ -399,6 +405,85 @@ 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().nth(64).is_none()
&& name.chars().any(visible)
&& !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)
@@ -631,6 +716,14 @@ mod tests {
"\u{3164}\u{FE0F}",
" \u{3000} ",
"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:?}");
}
@@ -638,6 +731,35 @@ 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…"),
("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));
// The documented limit counts characters, not bytes.
assert!(with_name(&"é".repeat(64)).is_ok());
assert!(with_name(&"é".repeat(65)).is_err());
+6 -1
View File
@@ -146,7 +146,12 @@ fn finish(app: &mut PhotocraftApp, mut d: Drag, click: Option<bool>) {
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);
+2
View File
@@ -988,6 +988,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)]
+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)]
+19 -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,
@@ -194,6 +185,24 @@ pub(super) fn history(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
}
/// 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",
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",
}
}
/// 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.
@@ -0,0 +1,42 @@
//! 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<String> {
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"));
}
/// 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");
// 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");
}
+3
View File
@@ -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