Appearance panel: a stroke colour on an unpainted zero-width stroke restores 1 pt too (#1253)

The case #1297 also covered: appearance.setItem with a colour and no weight.
This commit is contained in:
bflatastic committed 2026-10-12 07:25:31 +07:00
1 parent 2f64b5a86b
commit 8362223932
3 files changed
+18 -1

No files matched your search

+5
View File
@@ -522,6 +522,11 @@ fn set_item(s: &mut Session, p: &Value) -> Result<Value> {
s.edit("Appearance", |d, _| {
for id in &ids {
let Some(n) = d.node_mut(*id) else { continue };
if p.get("weight").is_none()
&& let Some(pa) = &paint
{
super::paint::restore_unpainted_stroke(&mut n.appearance, Some(idx), pa);
}
let bounds = n.geometric_bounds();
let Some(item) = n.appearance.items.get_mut(idx) else { continue };
let (pp, op, bl, vis, bounds) = match item {
+1 -1
View File
@@ -502,7 +502,7 @@ fn set_run_stroke(style: &mut CharStyle, paint: Paint) {
}
/// Use the existing 1 pt default when adding paint to an unpainted zero-width stroke.
fn restore_unpainted_stroke(ap: &mut Appearance, index: Option<usize>, paint: &Paint) {
pub(super) fn restore_unpainted_stroke(ap: &mut Appearance, index: Option<usize>, paint: &Paint) {
if !paint.is_none()
&& let Some(stroke) = ap.stroke_at_mut(index)
&& stroke.paint.is_none()
+12
View File
@@ -105,3 +105,15 @@ fn existing_weights_and_explicitly_zero_painted_strokes_keep_their_widths() {
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
assert_eq!(width(&s, id), 0.0, "fill edits and removing paint do not enable a stroke");
}
#[test]
fn appearance_panel_stroke_colour_restores_an_unpainted_zero_width_stroke() {
let (mut s, id) = fixture();
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
s.execute("stroke.set", &json!({"weight": 0})).unwrap();
s.execute("appearance.setItem", &json!({"index": 1, "color": "#00ff00"})).unwrap();
assert_eq!(width(&s, id), 1.0);
s.execute("appearance.setItem", &json!({"index": 1, "weight": 0})).unwrap();
s.execute("appearance.setItem", &json!({"index": 1, "color": "#0000ff"})).unwrap();
assert_eq!(width(&s, id), 0.0, "a painted stroke keeps an explicit zero width");
}