Review #987: test the next-object stroke with nothing selected; rustfmt
A rejected Stroke panel edit with nothing selected leaves the next object's stroke as it was; an accepted one sets its weight and dashes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
059bd82676
commit
de17a00eb2
|
|
@ -102,10 +102,8 @@ impl StrokeChange {
|
|||
Some(Value::Null) => Some(None),
|
||||
Some(Value::Array(a)) => {
|
||||
// Do not silently omit malformed segments and change the user's dash pattern.
|
||||
let values: Vec<f64> = a
|
||||
.iter()
|
||||
.map(|v| v.as_f64().ok_or_else(|| bad(cmd, format!("dash lengths must be numbers, got {v}"))))
|
||||
.collect::<Result<_>>()?;
|
||||
let values: Vec<f64> =
|
||||
a.iter().map(|v| v.as_f64().ok_or_else(|| bad(cmd, format!("dash lengths must be numbers, got {v}")))).collect::<Result<_>>()?;
|
||||
Some(Some(values).filter(|d| !d.is_empty()))
|
||||
}
|
||||
Some(v) => return Err(bad(cmd, format!("dash must be a list of lengths or null, got {v}"))),
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ fn fill_and_stroke_commands() {
|
|||
s.execute("paint.setFill", &json!({"gradient": {"kind": "radial"}})).unwrap();
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn stroke_rejects_invalid_dash_components_and_preserves_defaults_on_error() {
|
||||
let mut s = session();
|
||||
|
|
@ -158,6 +157,16 @@ fn stroke_rejects_invalid_dash_components_and_preserves_defaults_on_error() {
|
|||
s.execute("stroke.set", &json!({"weight": 7, "dash": [4, 2]})).unwrap();
|
||||
assert_eq!(s.paint.stroke_width, 7.0);
|
||||
assert_eq!(s.doc().unwrap().doc.node(id).unwrap().appearance.stroke().unwrap().width, 7.0);
|
||||
|
||||
// With nothing selected the panel sets up the next object drawn: a rejected edit doesn't.
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let next = s.new_art();
|
||||
assert!(s.execute("stroke.set", &json!({"weight": 12, "dash": [2, 2], "arrowAlign": "unknown"})).is_err());
|
||||
assert_eq!(s.new_art(), next);
|
||||
s.execute("stroke.set", &json!({"weight": 12, "dash": [2, 2]})).unwrap();
|
||||
let next = s.new_art();
|
||||
let stroke = next.stroke().unwrap();
|
||||
assert_eq!((stroke.width, stroke.dash.as_ref().map(|d| d.pattern.clone())), (12.0, Some(vec![2.0, 2.0])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue