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, withaddChildAtandaddIntermediateNodefromlayoutNode.ts), followed by the samebalance_nodethe 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_vectorsreplays 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§
Constants§
- DEFAULT_
MAX_ CHILDREN - Maximum children before
insert_node’s heuristic descends. Mirrorsfrontend/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_idthe 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
balanceNodeinfrontend/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, orErr(NodeNotFound)ifnode_idis not in the tree. Callers are responsible for clearingfocused_node_idif needed (spec §7.1). Collapses single-child parents. - find_
leaf_ containing_ block - Find the (first) leaf that has
block_idas its visible block OR as any member of itsblock_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
isEffectivelyMinimizedinfrontend/layout/lib/layoutInvariants.ts. Reducer guards use THIS (notis_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 untypedextracatch-all on this side. MirrorsisNodeLockedinfrontend/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’seffectiveStack,layoutStack.ts). - move_
stack_ member - Move
block_idtopositionrelative totarget_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 viaremove_stack_member, placed intotarget_block_id’s leaf via a position-aware push). Returnsfalse, leaving the tree untouched, when either block doesn’t exist in the tree. - move_
stack_ members - Move every block in
block_idsthat is not already intarget_block_id’s leaf into it, appended in the order given (each asmove_stack_memberwithStackMovePosition::Endwould), then makeactivate_block_idthe leaf’s visible tab when it is one of its members. - next_
visible_ member - Which tab becomes visible once the one at
removed_idxof the ORIGINAL stack is gone: the nearest eligible member to its right, else the nearest to its left.remainingis the stack with it removed;eligiblefilters (e.g. “still exists”). The one rule every removal path uses — frontendremoveMemberFromStackmirrors 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_idis not inlive_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_idto the tab stack of the pane holdingtarget_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 holdstarget_block_id. SPEC_PANE_TABS_REDUCER_COMMANDS_2026_09_18.md §3.2 (LayoutStackPush). - remove_
stack_ member - Remove
block_idfrom 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’sremoveMemberFromStack(frontend/layout/lib/stackMembers.ts). Returns false and changes nothing whenblock_idis 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, whenmove_stack_member(tree, block_id, target_block_id, ..)would delete that leaf:block_idis its only member andtarget_block_idlives in a different leaf.Nonefor 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
validateLayoutInvariantsinfrontend/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 andtracing::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).