Fix snap guides using sibling nodes in absolute coordinates

Snap targets are now siblings of the moving node (not root children),
converted to absolute coordinates. This fixes guides not reflecting
resized objects.
This commit is contained in:
Danila Poyarkov 2026-02-28 01:21:45 +03:00
parent 464a3b6e9c
commit 8e6d0a7f2f

View file

@ -534,8 +534,27 @@ export function useCanvasInput(canvasRef: Ref<HTMLCanvasElement | null>, store:
const bounds = computeSelectionBounds(selectedNodes)
if (bounds) {
const allNodes = store.graph.getChildren(store.graph.rootId)
const snap = computeSnap(store.state.selectedIds, bounds, allNodes)
// Snap against siblings in absolute coordinates
const firstId = [...d.originals.keys()][0]
const firstNode = store.graph.getNode(firstId)
const parentId = firstNode?.parentId ?? store.graph.rootId
const siblings = store.graph.getChildren(parentId)
const parentAbs = parentId !== store.graph.rootId
? store.graph.getAbsolutePosition(parentId)
: { x: 0, y: 0 }
const absTargets = siblings.map((n) => ({
...n,
x: n.x + parentAbs.x,
y: n.y + parentAbs.y
}))
// Convert moving bounds to absolute coords too
const absBounds = {
x: bounds.x + parentAbs.x,
y: bounds.y + parentAbs.y,
width: bounds.width,
height: bounds.height
}
const snap = computeSnap(store.state.selectedIds, absBounds, absTargets)
dx += snap.dx
dy += snap.dy
store.setSnapGuides(snap.guides)