Skip to main content

Module layout

Module layout 

Source
Expand description

Phase E.4.B Phase 4 — pure layout-tree helpers (Rust port of layoutTree.ts). Pure layout-tree functions for the srv reducer: traversal, pane-tab stacks, the write-point integrity passes (dangling blocks, invariants), balance_node, and the frontend’s tree actions as layout intents ([intent]). No I/O, no side effects.

Modules§

drop_split
The split of a hovered pane that a drop on one of its sides commits, by the drop direction the window sends (a redock of a floating pane, a move between window tabs, a pane docked beside another).
intent
Layout intents applied to a tree: a step-for-step port of the frontend’s tree actions (frontend/layout/lib/layoutTree.ts, with addChildAt and addIntermediateNode from layoutNode.ts), followed by the same balance_node the frontend runs after every action. The frontend applies an action locally as a prediction and srv’s result is the one that is stored, so the two must agree: intent_vectors replays one shared set of random sequences through both. Where the frontend would corrupt the tree (a move into the moved node’s own subtree, a swap of a node with its ancestor) or apply half an action (an invalid resize), srv refuses instead. SPEC_STRONG_REDUCER_AUTHORITY_LAYOUT_2026_06_30.md §4.
place
Where a pane sits in its tab, read from the tab’s layout tree: its rectangle as fractions of the tab’s area, and the edge it is on. The tree is the one place a pane’s size is kept, so this is the answer for anything that needs a pane’s place without a screen (a pinned pane unpinned into another tab, an agent asking where a pane is). It is the share each pane’s flex size gives it; the gap between panes and a minimized pane’s chip are the page’s to draw.

Enums§

LayoutError

Constants§

DEFAULT_MAX_CHILDREN
Maximum children before insert_node’s heuristic descends. Mirrors frontend/layout/lib/layoutTree.ts::DEFAULT_MAX_CHILDREN.
DEFAULT_NODE_SIZE
Default flex size for newly-inserted nodes. Mirrors frontend/layout/lib/types.ts::DefaultNodeSize.

Functions§

activate_stack_member
Make block_id the visible tab of the pane whose stack holds it. Returns false when no pane’s stack holds it. SPEC_PANE_TABS_REDUCER_COMMANDS_2026_09_18.md §3.2 (LayoutStackActivate).
balance_node
Port of balanceNode in frontend/layout/lib/layoutNode.ts. Recursively normalizes the tree: validates each node, alternates child flex direction, hoists redundant single-child-branch chains, drops empty branches, and collapses a branch with a single leaf child into that leaf.
delete_node
Remove the node with the given id from the tree. Returns Ok(()) on success, or Err(NodeNotFound) if node_id is not in the tree. Callers are responsible for clearing focused_node_id if needed (spec §7.1). Collapses single-child parents.
find_leaf_containing_block
Find the (first) leaf that has block_id as its visible block OR as any member of its block_stack. Unlike [find_node_id_by_block], which only matches the visible block, this finds the pane a background tab lives in. Returns the leaf node itself.
find_node_by_id
Find a node by id (immutable).
find_node_by_id_mut
Find a node by id (mutable).
is_effectively_minimized
True when a node renders as minimized: a locked leaf, or a branch whose every child is effectively minimized (a stacked chip strip). Mirrors isEffectivelyMinimized in frontend/layout/lib/layoutInvariants.ts. Reducer guards use THIS (not is_node_locked): a fully-collapsed branch has no branch-level marker in the display-mode model, but its stored size becomes load-bearing again the moment a child restores — so it must be just as untargetable as a minimized leaf.
is_node_locked
A minimize-locked node: a minimized leaf (minimizedSize), a slipped header (slipMinimize), or a dissolved column (columnDissolve). The fields are written by the frontend minimize subsystem and round-trip through the untyped extra catch-all on this side. Mirrors isNodeLocked in frontend/layout/lib/layoutMinimize.ts.
leaf_members
A leaf’s members: its block_stack, or [block_id] for a leaf with no stack (mirrors the frontend’s effectiveStack, layoutStack.ts).
move_stack_member
Move block_id to position relative to target_block_id: a same-leaf reorder when both are already members of one leaf’s stack, otherwise a cross-leaf move (removed from its source leaf via remove_stack_member, placed into target_block_id’s leaf via a position-aware push). Returns false, leaving the tree untouched, when either block doesn’t exist in the tree.
move_stack_members
Move every block in block_ids that is not already in target_block_id’s leaf into it, appended in the order given (each as move_stack_member with StackMovePosition::End would), then make activate_block_id the leaf’s visible tab when it is one of its members.
next_visible_member
Which tab becomes visible once the one at removed_idx of the ORIGINAL stack is gone: the nearest eligible member to its right, else the nearest to its left. remaining is the stack with it removed; eligible filters (e.g. “still exists”). The one rule every removal path uses — frontend removeMemberFromStack mirrors it (frontend/layout/lib/stackMembers.ts). SPEC_PANE_TABS_REDUCER_COMMANDS_2026_09_18.md §3.6.
prune_dangling_block_refs
Removes every leaf whose data.block_id is not in live_block_ids, using the same collapse semantics as an explicit user delete (delete_node’s single-child-parent promotion). Returns the number of leaves pruned (0 = tree was already clean — the common case, so this is cheap to call unconditionally on every write).
push_stack_member
Add block_id to the tab stack of the pane holding target_block_id (as its visible tab or a background member). A pane with no stack yet becomes a two-member stack. Already a member → only (re)activated if asked. Returns false when no pane holds target_block_id. SPEC_PANE_TABS_REDUCER_COMMANDS_2026_09_18.md §3.2 (LayoutStackPush).
remove_stack_member
Remove block_id from the stack of the leaf holding it, WITHOUT removing the leaf, when that leaf has other members. If it was the visible tab, the right-hand neighbour becomes visible (the new last member when it was rightmost) — the same rule as the frontend’s removeMemberFromStack (frontend/layout/lib/stackMembers.ts). Returns false and changes nothing when block_id is in no leaf or is its leaf’s only member (removing it means removing the leaf — the caller’s job). SPEC_PANE_TABS_REDUCER_COMMANDS_2026_09_18.md §3.4.
source_leaf_emptied_by_move
The node id of block_id’s leaf, when move_stack_member(tree, block_id, target_block_id, ..) would delete that leaf: block_id is its only member and target_block_id lives in a different leaf. None for every other move (reorder, multi-member source, missing blocks, self-target).
unplaced_blocks
The tab’s blocks that are in no pane of its tree: the other half of I1 (SPEC_PANE_TABS_REDUCER_COMMANDS_2026_09_18.md §3.1). Briefly true of a block on its way into a pane (a queued placement the frontend hasn’t applied yet); a block that stays unplaced is an orphan.
validate_layout_invariants
Layout doctor — structural invariant validation, mirroring validateLayoutInvariants in frontend/layout/lib/layoutInvariants.ts (keep the check lists in sync). Returns human-readable violation strings; empty = healthy. Never mutates. Reducer choke points call this after prune/enforce and tracing::error! any findings, so a corrupted tree is attributed to the write that produced it instead of being reconstructed later from db_layout archaeology (issue #2179).