MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / routeTreeKey

Function routeTreeKey

packages/core/src/runtime/router/tree.ts:36–240  ·  view source on GitHub ↗
(event: ZrevEvent, ctx: TreeRoutingCtx<T>)

Source from the content-addressed store, hash-verified

34 * - Asterisk (*): Expand all siblings
35 */
36export function routeTreeKey<T>(event: ZrevEvent, ctx: TreeRoutingCtx<T>): TreeRoutingResult {
37 if (event.kind !== "key") return Object.freeze({ consumed: false });
38 if (event.action !== "down") return Object.freeze({ consumed: false });
39 if (!ctx.keyboardNavigation) return Object.freeze({ consumed: false });
40
41 const { treeId, flatNodes, expanded, state } = ctx;
42 const { focusedKey } = state;
43 const nodeCount = flatNodes.length;
44
45 if (nodeCount === 0) return Object.freeze({ consumed: false });
46
47 // Find current focused index
48 const currentIndex = focusedKey !== null ? findNodeIndex(flatNodes, focusedKey) : -1;
49 const currentNode = currentIndex >= 0 ? flatNodes[currentIndex] : undefined;
50
51 // Arrow Up - move to previous visible node
52 if (event.key === ZR_KEY_UP) {
53 const nextIndex = currentIndex > 0 ? currentIndex - 1 : 0;
54 if (nextIndex === currentIndex && currentIndex >= 0) {
55 return Object.freeze({ consumed: true });
56 }
57
58 const nextNode = flatNodes[nextIndex];
59 if (nextNode) {
60 return Object.freeze({
61 nextFocusedKey: nextNode.key,
62 nodeToSelect: nextNode.key,
63 consumed: true,
64 });
65 }
66 return Object.freeze({ consumed: true });
67 }
68
69 // Arrow Down - move to next visible node
70 if (event.key === ZR_KEY_DOWN) {
71 const nextIndex = currentIndex < nodeCount - 1 ? currentIndex + 1 : nodeCount - 1;
72 if (nextIndex === currentIndex) {
73 return Object.freeze({ consumed: true });
74 }
75
76 const nextNode = flatNodes[nextIndex];
77 if (nextNode) {
78 return Object.freeze({
79 nextFocusedKey: nextNode.key,
80 nodeToSelect: nextNode.key,
81 consumed: true,
82 });
83 }
84 return Object.freeze({ consumed: true });
85 }
86
87 // Arrow Right - expand or move to first child
88 if (event.key === ZR_KEY_RIGHT) {
89 if (!currentNode) return Object.freeze({ consumed: true });
90
91 const isExpanded = expanded.includes(currentNode.key);
92
93 if (currentNode.hasChildren) {

Callers 8

routeFilePickerKeyDownFunction · 0.85
routeTreeKeyDownFunction · 0.85
tree.lazy.test.tsFile · 0.85
tree.edge.test.tsFile · 0.85

Calls 5

findNodeIndexFunction · 0.85
findFirstChildIndexFunction · 0.85
findParentIndexFunction · 0.85
expandAllSiblingsFunction · 0.85
toggleExpandedFunction · 0.50

Tested by

no test coverage detected