Recolor: a new color group keeps Global Adjust colors in Limit to Library

OK on colors opened alone snaps each color the Global Adjust changed to the
library's nearest color before saving the new group, as recolor.apply does for
a group's colors.
This commit is contained in:
dotCooCoo
2026-11-01 18:33:20 -08:00
parent d46284c52c
commit 1c6720a85c
2 changed files with 31 additions and 2 deletions
+13 -2
View File
@@ -353,12 +353,23 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
let mut d = d.clone();
sync(app, &mut d);
if d.bool("__newGroup") {
// The new colors with the Global Adjust, as `recolor.apply` gives them to a group.
// The new colors with the Global Adjust, snapped to Limit to Library, as `recolor.apply`
// gives them to a group.
let adjust = global_adjust(adjust_values(&d));
let limit = d.str("limitTo");
let palette = Some(limit).filter(|l| !l.is_empty()).and_then(|l| swatchlib::limit_palette(&app.session, &l));
let colors: Vec<Value> = rows(&d)
.into_iter()
.filter(|r| !excluded(r))
.map(|r| to_color(&r).filter(|_| !adjust.is_identity()).map_or_else(|| r["to"].clone(), |c| key(&adjust.apply(c))))
.map(|r| {
to_color(&r).filter(|_| !adjust.is_identity()).map_or_else(
|| r["to"].clone(),
|c| {
let c = adjust.apply(c);
key(&palette.as_ref().map_or(c, |p| p.nearest(c)))
},
)
})
.collect();
return form::commit_preview(app, "swatch.newGroup", json!({"name": d.str("groupName"), "colors": colors, "keepModel": true}));
}
+18
View File
@@ -642,6 +642,24 @@ fn global_adjust_changes_every_color_at_once() {
}
}
/// Colors opened alone with Limit to Library: OK saves the new colors with the Global Adjust as a
/// new color group, each snapped to the library again, as `recolor.apply` gives them to a group.
#[test]
fn global_adjust_on_a_new_group_keeps_its_colors_in_the_library() {
let mut app = app();
app.run("ui.recolorDialog", json!({"colors": ["#123456", "#abcdef"], "library": ""})).unwrap();
assert_eq!(field(&app, "limitTo"), "web-safe-216");
let web = |k: &Value| vectorcraft_engine::cmd::color_value(k).unwrap().to_rgb().iter().all(|v| ((v * 5.0).round() - v * 5.0).abs() < 1e-3);
let rows: Vec<Value> = field(&app, "rows").as_array().unwrap().iter().map(|r| r["to"].clone()).collect();
assert!(rows.iter().all(web), "the rows open snapped: {rows:?}");
set(&mut app, "globalAdjust", json!({"brightness": -60}));
dialogs::confirm(&mut app).unwrap();
let keys = group_keys(&app, "Color Group");
assert_eq!(keys.len(), 2);
assert_ne!(keys, rows, "the Global Adjust changed the colors");
assert!(keys.iter().all(web), "every group color is a library color: {keys:?}");
}
/// The Assign tab's per-row hex fields are named by their row, not all "Color": a screen reader can
/// tell the second from the first.
#[test]