feat(sidebar): navigate the connection tree with arrow keys

This commit is contained in:
zhangyaxi authored and GitHub committed 2026-09-05 13:25:03 +08:00
1 parent a196a68d38
commit 0b8c7d700a
8 files changed
+573

No files matched your search

@@ -1399,6 +1399,10 @@ const pasteHandlerRegistry = createSidebarPasteHandlerRegistry();
provide(sidebarTreeContextKey, {
getVisibleNodes: () => selectableVisibleNodes.value,
getVisibleNodeIndex: (id: string) => selectableVisibleNodeIndexById.value.get(id) ?? -1,
getVisibleFlatNodes: () => flatNodes.value.filter((item) => !isSidebarTableSearchControlNode(item.node)),
focusTreeNode: (nodeId: string) => {
void focusSidebarTreeNode(nodeId);
},
getProjectedConnectionIds: () => projectedConnectionIds.value,
// Cover both sides of the input debounce: the immediate query prevents a
// collapse while a projection is about to start, and the deferred query
@@ -1490,6 +1494,24 @@ async function scrollToSidebarNode(nodeId: string, options?: { align?: SidebarNo
}
}
// Arrow-key navigation moves the selection first; only after the row re-renders
// as the tabbable one (tabindex follows selection) can focus follow it.
async function focusSidebarTreeNode(nodeId: string) {
await nextTick();
// Scroll before querying the row: the virtualized tree only keeps rows in
// the materialized window in the DOM, so querying first would never find an
// out-of-window row and focus would stall at the window edge. Scrolling is
// index-driven (no DOM lookup) and a no-op when the row is already visible;
// one render frame lets RecycleScroller materialize the target row.
await scrollToSidebarNode(nodeId);
const root = rootRef.value;
if (!root) return;
await waitForSidebarRenderFrame();
const row = root.querySelector<HTMLElement>(`[data-node-id="${CSS.escape(nodeId)}"]`);
if (!row) return;
row.focus({ preventScroll: true });
}
function clearSidebarSelection() {
// Clicking the blank area of the tree clears the current selection. Row
// clicks call event.stopPropagation(), so this only fires for blank clicks