mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-28 11:47:21 -06:00
Brushes, patterns and artboards: new and renamed items have their names trimmed
brush.new, brush.duplicate, object.pattern.make,
object.pattern.saveCopy, artboard.new and artboard.setProps kept the
name they were given as it was, and brush.options and pattern.options
kept the white space around a new name. So a script could make a brush
" Nib" beside "Nib", and a blank name made a brush, a pattern or an
artboard named with the blank. Artboard Options sends its Name field
as typed, so clearing it named the artboard "". The Brush Options
dialog, the Pattern Options panel and the Artboards panel trim the
names they send.
The eight commands now trim the name, and the brush and pattern
commands compare the trimmed name with the names there are. In
brush.new, brush.duplicate, object.pattern.make,
object.pattern.saveCopy and artboard.new, a blank name gives the name
the command gives when there is none: "New Calligraphic Brush" and the
other default brush names, "<name> copy", "New Pattern N",
"<pattern> copy" and "Artboard N". brush.options and pattern.options
keep the name when the new one is blank, and artboard.setProps gives a
blank one the artboard's default name, Artboard N for the Nth
artboard. Duplicate Brush and Save a Copy name the copy of a brush or
pattern whose saved name has white space around it from the trimmed
name (" Old " gives "Old copy").
Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
@@ -267,6 +267,41 @@ fn save_a_copy_while_editing() {
|
||||
assert!(doc(&s).pattern("Dots copy").is_some());
|
||||
}
|
||||
|
||||
/// Make, Save a Copy and Pattern Options trim the name they are given, as the Pattern Options
|
||||
/// panel does; the trimmed name is the one compared with the names there are, and a blank name
|
||||
/// gives the name the command gives when there is none.
|
||||
#[test]
|
||||
fn made_copied_and_renamed_patterns_trim_their_names() {
|
||||
let mut s = session();
|
||||
make_dots(&mut s);
|
||||
let make = |s: &mut Session, name: &str| {
|
||||
let r = rect(s, 0.0, 0.0, 10.0, 10.0);
|
||||
s.execute("object.pattern.make", &json!({"ids": [r.0], "name": name, "edit": false})).unwrap()["name"].clone()
|
||||
};
|
||||
assert_eq!(make(&mut s, " Grid \t"), "Grid");
|
||||
assert_eq!(make(&mut s, " Dots"), "Dots 2");
|
||||
assert_eq!(make(&mut s, ""), "New Pattern 1");
|
||||
assert_eq!(make(&mut s, " \t "), "New Pattern 2");
|
||||
s.execute("object.pattern.edit", &json!({"name": "Grid"})).unwrap();
|
||||
assert_eq!(s.execute("object.pattern.saveCopy", &json!({"name": " Lines\t"})).unwrap()["name"], "Lines");
|
||||
assert_eq!(s.execute("object.pattern.saveCopy", &json!({"name": " "})).unwrap()["name"], "Grid copy");
|
||||
s.execute("object.pattern.done", &json!({})).unwrap();
|
||||
assert_eq!(s.execute("pattern.options", &json!({"name": "Dots 2", "newName": " Spots "})).unwrap()["name"], "Spots");
|
||||
assert_eq!(s.execute("pattern.options", &json!({"name": "Spots", "newName": " "})).unwrap()["name"], "Spots");
|
||||
let e = s.execute("pattern.options", &json!({"name": "Spots", "newName": " Lines"})).unwrap_err().to_string();
|
||||
assert!(e.contains("a pattern named `Lines` exists"), "{e}");
|
||||
// Save a Copy names the copy of a pattern whose saved name has white space around it, as a
|
||||
// saved file can hold, from the trimmed name (" Old " gives "Old copy").
|
||||
let d = Arc::make_mut(&mut s.doc_mut().unwrap().doc);
|
||||
d.patterns.iter_mut().filter(|p| p.name == "Grid copy").for_each(|p| p.name = " Old ".into());
|
||||
s.execute("object.pattern.edit", &json!({"name": " Old "})).unwrap();
|
||||
assert_eq!(s.execute("object.pattern.saveCopy", &json!({})).unwrap()["name"], "Old copy");
|
||||
s.execute("object.pattern.cancel", &json!({})).unwrap();
|
||||
let names: Vec<&str> = doc(&s).patterns.iter().map(|p| p.name.as_str()).collect();
|
||||
assert_eq!(names, ["Dots", "Grid", "Spots", "New Pattern 1", "New Pattern 2", "Lines", " Old ", "Old copy"]);
|
||||
assert!(doc(&s).swatch("Spots").is_some() && doc(&s).swatch(" Spots ").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undo_make_pattern() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user