Skip to content

Commit 102ac8c

Browse files
idaivclaude
andauthored
[Studio UI] Add Home/End key navigation to tree
Home jumps to the first visible node, End to the last. Consolidated the four navigation functions (next/prev/first/last) into a single gotoNode helper to stay within the file line limit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e7b46ce commit 102ac8c

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

assets/js/src/core/components/element-tree/node/tree-node.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,19 @@ const TreeNode = forwardRef(function ForwardedTreeNode ({
167167
}
168168

169169
if (event.key === 'ArrowDown') {
170-
gotoNextNode(event)
170+
gotoNode(event, 1)
171171
}
172172

173173
if (event.key === 'ArrowUp') {
174-
gotoPreviousNode(event)
174+
gotoNode(event, -1)
175+
}
176+
177+
if (event.key === 'Home') {
178+
gotoNode(event, 'first')
179+
}
180+
181+
if (event.key === 'End') {
182+
gotoNode(event, 'last')
175183
}
176184
}
177185

@@ -183,23 +191,14 @@ const TreeNode = forwardRef(function ForwardedTreeNode ({
183191
setExpanded(false)
184192
}
185193

186-
function gotoNextNode (event: KeyboardEvent): void {
187-
event.preventDefault()
188-
189-
const index = nodeOrder!().indexOf(internalKey)
190-
191-
if (index < nodeOrder!().length - 1) {
192-
nodesRefs!.current[nodeOrder!()[index + 1]].el.focus()
193-
}
194-
}
195-
196-
function gotoPreviousNode (event: KeyboardEvent): void {
194+
function gotoNode (event: KeyboardEvent, offset: number | 'first' | 'last'): void {
197195
event.preventDefault()
198-
199-
const index = nodeOrder!().indexOf(internalKey)
200-
201-
if (index > 0) {
202-
nodesRefs!.current[nodeOrder!()[index - 1]].el.focus()
196+
const order = nodeOrder!()
197+
if (order.length === 0) return
198+
const current = order.indexOf(internalKey)
199+
const target = offset === 'first' ? 0 : offset === 'last' ? order.length - 1 : current + offset
200+
if (target >= 0 && target < order.length) {
201+
nodesRefs!.current[order[target]].el.focus()
203202
}
204203
}
205204

0 commit comments

Comments
 (0)