Define Brush Preset: skip a taken "Sampled Brush N" ignoring case (#18228)

The preset store matches names ignoring ASCII case, so a typed
"sampled brush 1" was still replaced by the default "Sampled Brush 1".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dholzricandClaude Opus 5.5 committed 2026-12-01 18:43:23 -06:00
1 parent f525f28080
commit 71e3c51be4
2 files changed
+10 -2

No files matched your search

@@ -7,9 +7,10 @@ use photocraft_doc::vector::PathOp;
pub(super) fn define_brush_preset(s: &mut Session, p: &Value) -> Result<Value> {
let typed = p.get("name").and_then(Value::as_str).map(str::trim).filter(|n| !n.is_empty());
// The default counts the defaults stored this session; presets that merely share the name don't raise it (#18228). A
// number a preset already uses is skipped, since storing under that name would replace that preset.
// number a preset already uses is skipped, since storing under that name would replace that preset; the store matches
// names ignoring ASCII case, so this does too.
let mut number = s.tools.sampled_brushes.saturating_add(1);
while typed.is_none() && s.tools.presets.iter().any(|b| b.name == format!("Sampled Brush {number}")) {
while typed.is_none() && s.tools.presets.iter().any(|b| b.name.eq_ignore_ascii_case(&format!("Sampled Brush {number}"))) {
number = number.saturating_add(1);
}
let name = typed.map_or_else(|| format!("Sampled Brush {number}"), str::to_string);
@@ -78,6 +78,13 @@ fn a_taken_number_is_skipped_and_the_preset_is_kept() {
let second = define(&mut s, json!({}));
assert!(![first.as_str(), "Sampled Brush 1"].contains(&second.as_str()), "{second}");
assert_eq!(user_presets(&s).len(), 3, "{:?}", user_presets(&s));
// The store matches names ignoring case, so a typed "sampled brush 1" is taken too.
let mut s = session();
define(&mut s, json!({"name": "sampled brush 1"}));
let first = define(&mut s, json!({}));
assert!(!first.eq_ignore_ascii_case("sampled brush 1"), "{first}");
assert_eq!(user_presets(&s).len(), 2, "{:?}", user_presets(&s));
}
/// A call that stores no preset leaves the number as it is.