mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Recolor Artwork: find a renamed group's name over its preview
Opening Recolor Artwork on a color group while the open dialog previewed a rename of that group failed with "no colour group", because the name was checked against the previewed document before Cancel restored it. The name is now checked against the document without the replaced dialog's preview. An unknown group still fails and leaves the open dialog as it is.
This commit is contained in:
1 parent
ec3fe96195
commit
b7c98147e9
2 files changed
+29
-1
No files matched your search
@@ -200,8 +200,14 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
let st = app.session.active().ok_or("no document open")?;
|
||||
let art = !st.selection.is_empty();
|
||||
let group = p.get("group").and_then(Value::as_str);
|
||||
// The group is looked for in the document without the preview of the dialog this one replaces
|
||||
// (which can rename the group), as that dialog's Cancel below leaves it.
|
||||
let unpreviewed = match &st.interaction {
|
||||
Some(it) if app.ui.dialog.is_some() => &it.doc,
|
||||
_ => &st.doc,
|
||||
};
|
||||
if let Some(g) = group
|
||||
&& !st.doc.swatch_groups.iter().any(|x| x.name == g)
|
||||
&& !unpreviewed.swatch_groups.iter().any(|x| x.name == g)
|
||||
{
|
||||
return Err(format!("no colour group `{g}`"));
|
||||
}
|
||||
|
||||
@@ -2075,6 +2075,28 @@ fn reopening_a_group_over_its_preview_starts_on_the_groups_colours() {
|
||||
dialogs::cancel(&mut app);
|
||||
}
|
||||
|
||||
/// Recolor Artwork opened on a colour group over a preview that renames it finds the group by its
|
||||
/// name without the preview; an unknown group leaves the open dialog as it is.
|
||||
#[test]
|
||||
fn reopening_a_group_over_a_preview_that_renames_it_finds_the_group() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
art(&mut app, &["#ff0000", "#0000ff"]);
|
||||
let before = group_keys(&app, "Brights");
|
||||
app.run("ui.recolorDialog", json!({"group": "Brights"})).unwrap();
|
||||
dialog_frame(&mut app, &ctx);
|
||||
set(&mut app, "groupName", json!("Renamed"));
|
||||
dialog_frame(&mut app, &ctx);
|
||||
let named = |app: &VectorcraftApp, n: &str| app.session.doc().unwrap().doc.swatch_groups.iter().any(|g| g.name == n);
|
||||
assert!(named(&app, "Renamed") && !named(&app, "Brights"), "the preview renames the group");
|
||||
assert!(app.run("ui.recolorDialog", json!({"group": "Nope"})).is_err());
|
||||
assert_eq!(field(&app, "groupName"), json!("Renamed"), "an unknown group leaves the dialog open");
|
||||
app.run("ui.recolorDialog", json!({"group": "Brights"})).unwrap();
|
||||
assert!(named(&app, "Brights") && !named(&app, "Renamed"), "the preview is rolled back");
|
||||
assert_eq!(field(&app, "__assign"), json!(before), "the new dialog starts on the group's colours");
|
||||
dialogs::cancel(&mut app);
|
||||
}
|
||||
|
||||
/// Every paint under `v`, in order: its color, the swatch it is linked to and its tint.
|
||||
fn paints_in(v: &Value, out: &mut Vec<(Color, Option<String>, f64)>) {
|
||||
match v {
|
||||
|
||||
Reference in new issue
Block a user