ensure_group_node

Function ensure_group_node 

Source
fn ensure_group_node(node: &mut LayoutNode)
Expand description

If node is a leaf (has data), promote it to a group by wrapping its data in an intermediate child. Mirrors TypeScript addIntermediateNode in frontend/layout/lib/layoutTree.ts.

After this call:

  • node.data is None and node.children is non-empty.
  • The intermediate child receives the node’s ORIGINAL ID so any frontend reference (e.g. focusedNodeId) still points at the leaf data after promotion.
  • The group wrapper gets a fresh UUID, and its flex direction is the reverse of the original leaf’s so the new sibling axis is perpendicular to the parent’s (matches TS layout semantics).

No-op when node is already a group (no data).