feat: adjust scroll to selected node position to top-left area (#25403)

This commit is contained in:
lyzno1 2025-09-09 14:58:42 +08:00 committed by GitHub
parent dc16f1b65a
commit 1c8850fc95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -97,13 +97,14 @@ export function setupScrollToNodeListener(
const node = nodes.find(n => n.id === nodeId)
if (node) {
// Use ReactFlow's fitView API to scroll to the node
reactflow.fitView({
nodes: [node],
padding: 0.2,
duration: 800,
minZoom: 0.5,
maxZoom: 1,
})
const nodePosition = { x: node.position.x, y: node.position.y }
// Calculate position to place node in top-left area
// Move the center point right and down to show node in top-left
const targetX = nodePosition.x + window.innerWidth * 0.25
const targetY = nodePosition.y + window.innerHeight * 0.25
reactflow.setCenter(targetX, targetY, { zoom: 1, duration: 800 })
}
}
}