MCPcopy
hub / github.com/wavetermdev/waveterm / validateFocusedNode

Method validateFocusedNode

frontend/layout/lib/layoutModel.ts:908–929  ·  view source on GitHub ↗

* Checks whether the focused node id has changed and, if so, whether to update the focused node stack. If the focused node was deleted, will pop the latest value from the stack. * @param leafOrder The new leaf order array to use when searching for stale nodes in the stack.

(leafOrder: LeafOrderEntry[])

Source from the content-addressed store, hash-verified

906 * @param leafOrder The new leaf order array to use when searching for stale nodes in the stack.
907 */
908 private validateFocusedNode(leafOrder: LeafOrderEntry[]) {
909 if (this.treeState.focusedNodeId !== this.focusedNodeId) {
910 // Remove duplicates and stale entries from focus stack.
911 const newFocusedNodeIdStack: string[] = [];
912 for (const id of this.focusedNodeIdStack) {
913 if (leafOrder.find((leafEntry) => leafEntry?.nodeid === id) && !newFocusedNodeIdStack.includes(id))
914 newFocusedNodeIdStack.push(id);
915 }
916 this.focusedNodeIdStack = newFocusedNodeIdStack;
917
918 // Update the focused node and stack based on the changes in the tree state.
919 if (!this.treeState.focusedNodeId) {
920 if (this.focusedNodeIdStack.length > 0) {
921 this.treeState.focusedNodeId = this.focusedNodeIdStack.shift();
922 } else if (leafOrder.length > 0) {
923 // If no nodes are in the stack, use the top left node in the layout.
924 this.treeState.focusedNodeId = leafOrder[0].nodeid;
925 }
926 }
927 this.focusedNodeIdStack.unshift(this.treeState.focusedNodeId);
928 }
929 }
930
931 /**
932 * When a layout is modified and only one leaf is remaining, we need to make sure it is no longer magnified.

Callers 1

updateTreeMethod · 0.95

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected