Merge pull request #8456 from dotCooCoo/feat/swatches-color-group-options

Swatches: Color Group Options renames the selected color group
This commit is contained in:
BFlat
2026-11-19 14:58:45 +07:00
committed by GitHub
46 changed files with 662 additions and 8 deletions
+66
View File
@@ -569,6 +569,72 @@ fn ungroup_and_sort_by_kind_are_one_undo_step_each() {
assert_eq!(n[n.iter().position(|x| x == "Orange").unwrap() + 1], "Ocean", "the spot colour comes after the process ones, then the gradients");
}
/// Color Group Options renames a color group alone, as one undo step: its swatches, their colors
/// and the art linked to them stay as they are. A name another group or a swatch has, an empty
/// name and a parameter that is missing or not a string are errors that change nothing, and the
/// group's own name records no undo step.
#[test]
fn rename_group_renames_only_the_group_in_one_undo_step() {
let mut s = session();
run(&mut s, "swatch.edit", json!({"name": "Bright Red", "global": true}));
let a = rect_filled(&mut s, json!({"swatch": "Bright Red"}));
let linked = fill(&s, a);
let members = names(&s, Some("Brights"));
let before = doc(&s).clone();
let undo = undo_len(&s);
assert_eq!(run(&mut s, "swatch.renameGroup", json!({"group": "Brights", "name": " Vivid Colors "}))["name"], "Vivid Colors");
assert!(doc(&s).swatch_groups.iter().all(|g| g.name != "Brights"));
assert_eq!(names(&s, Some("Vivid Colors")), members);
assert_eq!(fill(&s, a), linked, "linked art keeps its swatch and color");
assert_eq!(undo_len(&s), undo + 1);
run(&mut s, "edit.undo", json!({}));
assert_eq!(*doc(&s), before);
run(&mut s, "edit.redo", json!({}));
assert_eq!(names(&s, Some("Vivid Colors")), members);
let renamed = doc(&s).clone();
// The group's own name, trimmed, changes nothing.
assert_eq!(run(&mut s, "swatch.renameGroup", json!({"group": "Vivid Colors", "name": " Vivid Colors"}))["name"], "Vivid Colors");
assert_eq!(undo_len(&s), undo + 1);
let refused = [
json!({"group": "Vivid Colors", "name": "Grays"}),
json!({"group": "Vivid Colors", "name": "White"}),
json!({"group": "Vivid Colors", "name": "[None]"}),
json!({"group": "Vivid Colors", "name": "[Registration]"}),
json!({"group": "Vivid Colors", "name": ""}),
json!({"group": "Vivid Colors", "name": " "}),
json!({"group": "Vivid Colors"}),
json!({"group": "Vivid Colors", "name": null}),
json!({"group": "Vivid Colors", "name": 5}),
json!({"name": "Bold"}),
json!({"group": 5, "name": "Bold"}),
json!({"group": "Nope", "name": "Bold"}),
json!({"group": "White", "name": "Bold"}),
];
for p in refused {
assert!(s.execute("swatch.renameGroup", &p).is_err(), "{p}");
assert_eq!(*doc(&s), renamed, "{p}");
assert_eq!(undo_len(&s), undo + 1, "{p}");
}
}
/// A color group renamed while a drag is still in progress keeps its new name when the drag is
/// canceled: the drag becomes a step of its own first, and the rename is the next step.
#[test]
fn rename_group_during_a_drag_is_a_step_of_its_own() {
let mut s = session();
rect_filled(&mut s, json!({"swatch": "Bright Red"}));
let undo = undo_len(&s);
s.begin_interaction("Move").unwrap();
s.preview("object.move", &json!({"dx": 7, "dy": 0})).unwrap();
run(&mut s, "swatch.renameGroup", json!({"group": "Brights", "name": "Vivid"}));
s.cancel_interaction().ok();
assert!(doc(&s).swatch_groups.iter().any(|g| g.name == "Vivid"), "canceling the drag keeps the rename");
assert_eq!(undo_len(&s), undo + 2, "the drag and the rename are two steps");
run(&mut s, "edit.undo", json!({}));
assert!(doc(&s).swatch_groups.iter().any(|g| g.name == "Brights"), "Undo takes back the rename alone");
assert_eq!(undo_len(&s), undo + 1);
}
#[test]
fn a_cmyk_document_starts_with_cmyk_swatches_and_stores_new_colours_as_cmyk() {
use vectorcraft_color::Color;