Layers: a layer or gap color with an alpha part is refused instead of losing its alpha

layer.setProps, layer.new, layer.newSublayer and livePaint.gapOptions read
an 8-digit hex color such as #ff000080 as #ff0000 and set it without its
alpha. They now refuse it with the error a bad color already gets, and
change nothing. #rgba was already refused. #rrggbb, #rgb, a preset index
and a preset name are read as before.
This commit is contained in:
dotCooCoo authored and bflatastic committed 2026-11-04 18:29:17 +07:00
1 parent 12508e6c60
commit d79f5ccb75
6 files changed
+62 -6

No files matched your search

+19
View File
@@ -2244,6 +2244,25 @@ fn live_paint_gap_detection_stops_paint_at_a_gap() {
assert!(node(&s, g).extras().live_paint_gaps.is_none());
}
/// A Gap Preview Color with an alpha part (`#rrggbbaa` or `#rgba`) is refused and changes nothing;
/// `#rrggbb` and a layer color's name still set it.
#[test]
fn a_gap_color_with_an_alpha_part_is_refused() {
let mut s = session();
let g = live_square_with_a_gap(&mut s);
let depth = s.doc().unwrap().history.undo.len();
for bad in ["#00ff0080", "00ff0080", "#0f08"] {
let err = s.execute("livePaint.gapOptions", &json!({"id": g.0, "color": bad})).unwrap_err().to_string();
assert!(err.contains(&format!("`{bad}` is not a colour (#rrggbb or a preset name)")), "{bad}: {err}");
}
assert_eq!(s.doc().unwrap().history.undo.len(), depth);
assert_eq!(gap_options(&s, g).color, [0xff, 0x4f, 0x4f]);
s.execute("livePaint.gapOptions", &json!({"id": g.0, "color": "#00ff00"})).unwrap();
assert_eq!(gap_options(&s, g).color, [0, 0xff, 0]);
s.execute("livePaint.gapOptions", &json!({"id": g.0, "color": "Green"})).unwrap();
assert_eq!(gap_options(&s, g).color, [0x4f, 0xff, 0x4f]);
}
#[test]
fn medium_and_large_gaps_stop_paint_at_wider_gaps() {
// Squares whose ends stop 5 pt and 9 pt short of their starts: each size closes the gaps up
+26
View File
@@ -375,6 +375,32 @@ fn layer_options_validate_and_template_locks_and_dims() {
assert_eq!((summary["preview"].clone(), summary["dimImages"].clone()), (json!(false), json!(30)));
}
/// A layer color with an alpha part (`#rrggbbaa` or `#rgba`) is refused by Layer Options, New
/// Layer and New Sublayer and changes nothing; `#rrggbb` and a preset name still set it.
#[test]
fn a_layer_color_with_an_alpha_part_is_refused() {
let mut s = session();
let (layer, ..) = tree(&mut s);
let color = |s: &Session| match node(s, layer).kind {
NodeKind::Layer { color, .. } => color,
_ => panic!("not a layer"),
};
let before = (color(&s), undos(&s));
for bad in ["#ff000080", "ff000080", " #FF000080 ", "#f008"] {
let err = s.execute("layer.setProps", &json!({"id": layer.0, "color": bad})).unwrap_err().to_string();
assert!(err.contains(&format!("`{bad}` is not a colour (#rrggbb or a preset name)")), "{bad}: {err}");
assert!(s.execute("layer.new", &json!({"color": bad})).is_err(), "{bad}");
assert!(s.execute("layer.newSublayer", &json!({"parent": layer.0, "color": bad})).is_err(), "{bad}");
}
assert_eq!((color(&s), undos(&s)), before);
run(&mut s, "layer.setProps", json!({"id": layer.0, "color": "#ff0000"}));
assert_eq!(color(&s), LayerColor::Custom([0xff, 0, 0]));
run(&mut s, "layer.setProps", json!({"id": layer.0, "color": "Green"}));
assert_eq!(color(&s), LayerColor::Preset(2));
let new = id(&run(&mut s, "layer.new", json!({"color": "#00ff00"})));
assert!(matches!(node(&s, new).kind, NodeKind::Layer { color: LayerColor::Custom([0, 0xff, 0]), .. }));
}
#[test]
fn new_layers_go_above_the_current_one_at_its_level() {
let mut s = session();