From e565f8663290e162bc347d7d4adbafb5be37ae0f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 23 May 2026 18:30:32 +0100 Subject: [PATCH] Resolve navigation focus from final viewport --- .../src/lib/EpiphanyGraphViewer.tsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx b/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx index 77acfb1..169329a 100644 --- a/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx +++ b/web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx @@ -527,17 +527,32 @@ export function EpiphanyGraphViewer({ }, viewportFlightRef, setTransforms, - () => { + (finalTransform) => { + const centeredNode = + activeLayout + ? nodeNearestViewportCenter( + activeLayout.nodes, + finalTransform, + viewportSize.width, + viewportSize.height, + ) + : targetNode; + const focusedNode = centeredNode ?? targetNode; + const focusedSelection: ViewerSelection = { + kind: "node", + graphKey: activeGraphKey, + nodeId: focusedNode.id, + }; commitViewportFocusSelection( - navigationSelection, - targetNode, + focusedSelection, + focusedNode, skipSelectionFocusRef, focusedSelectionKeyRef, focusedNodeRef, updateSelection, ); activeNavigationKeyRef.current = null; - onNavigationComplete?.(navigationSelection); + onNavigationComplete?.(focusedSelection); }, ); }, [ @@ -2166,7 +2181,7 @@ function startViewportFlight( }, flightRef: React.MutableRefObject, setTransforms: React.Dispatch>>, - onComplete: () => void, + onComplete: (finalTransform: ViewTransform) => void, ) { cancelViewportFlight(flightRef); const flightId = (flightRef.current?.id ?? 0) + 1; @@ -2207,7 +2222,10 @@ function startViewportFlight( } flightRef.current = null; - onComplete(); + onComplete({ + ...target, + userMoved: true, + }); }; flightRef.current = {