.fig export: an override that clears a maximum size writes it as infinite

Like an unset axis, a cleared maximum was written as 0 and could
collapse the layer (CodeRabbit review on #1152).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ricardo
2026-10-22 13:16:16 -06:00
co-authored by Claude Opus 5.5
parent 70a080af5b
commit 2c044f6b80
2 changed files with 20 additions and 1 deletions
+3 -1
View File
@@ -2569,7 +2569,9 @@ fn unset(key: &str) -> Option<Kv<'static>> {
"cornerSmoothing" | "stackChildPrimaryGrow" => fl(0.0),
"stackMode" => e("NONE"),
"stackChildAlignSelf" | "stackPositioning" => e("AUTO"),
"minSize" | "maxSize" => o(vec![("value", xy(0.0, 0.0))]),
"minSize" => o(vec![("value", xy(0.0, 0.0))]),
// No maximum is infinite (a maximum of 0 collapses the layer).
"maxSize" => o(vec![("value", o(vec![("x", Kv::Float(f32::INFINITY)), ("y", Kv::Float(f32::INFINITY))]))]),
"gridColumnSpan" | "gridRowSpan" | "maxLines" => int(0),
"scrollDirection" => e("NONE"),
"scrollBehavior" => e("SCROLLS"),
+17
View File
@@ -1319,3 +1319,20 @@ fn set_properties_round_trip() {
let NodeKind::Instance { props, .. } = &i.kind else { panic!() };
assert_eq!(props.get("Label"), Some(&Value::String("Hi".into())));
}
#[test]
fn an_instance_without_its_mains_maximum_size_overrides_it_with_infinity() {
let mut doc = Document::new("File");
let page = doc.first_page().unwrap();
let main = doc.create(page, NodeKind::Component { description: String::new(), props: BTreeMap::new() }, "Box", 0.0, 0.0, 100.0, 40.0).unwrap();
doc.node_mut(main).unwrap().child_layout.max_w = Some(300.0);
doc.create(page, NodeKind::Instance { component: main, props: BTreeMap::new() }, "Box", 0.0, 100.0, 100.0, 40.0).unwrap();
let (bytes, _) = export(&doc, None).unwrap();
let archive = Archive::open(&bytes).unwrap();
let (schema, message) = decode_canvas(&archive.canvas).unwrap();
let msg = schema.decode_message(schema.find("Message").unwrap(), &message).unwrap();
let inst = msg.get("nodeChanges").unwrap().list().iter().find(|n| n.get("type").and_then(Kv::str) == Some("INSTANCE")).unwrap();
let overrides = inst.get("symbolData").unwrap().get("symbolOverrides").unwrap().list();
let max = overrides.iter().find_map(|o| o.get("maxSize")).unwrap().get("value").unwrap();
assert_eq!((max.get("x"), max.get("y")), (Some(&Kv::Float(f32::INFINITY)), Some(&Kv::Float(f32::INFINITY))));
}