Skip to content

Commit dd48e47

Browse files
committed
fix(core): use valid handle result as connecting handle (#1932)
* fix(core): use valid handle result as connecting handle Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
1 parent 3c96b38 commit dd48e47

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

.changeset/orange-ligers-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Use toHandle from valid handle check as target handle in ongoing connections

packages/core/src/composables/useHandle.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export function useHandle({
207207
edges.value,
208208
nodes.value,
209209
findNode,
210+
nodeLookup.value,
210211
)
211212

212213
handleDomNode = result.handleDomNode
@@ -242,18 +243,19 @@ export function useHandle({
242243
return
243244
}
244245

246+
const connectingHandle = closestHandle ?? result.toHandle
245247
updateConnection(
246-
closestHandle && isValid
248+
connectingHandle && isValid
247249
? rendererPointToPoint(
248250
{
249-
x: closestHandle.x,
250-
y: closestHandle.y,
251+
x: connectingHandle.x,
252+
y: connectingHandle.y,
251253
},
252254
viewport.value,
253255
)
254256
: connectionPosition,
255257
result.toHandle,
256-
getConnectionStatus(!!closestHandle, isValid),
258+
getConnectionStatus(!!connectingHandle, isValid),
257259
)
258260

259261
previousConnection = newConnection
@@ -377,6 +379,7 @@ export function useHandle({
377379
edges.value,
378380
nodes.value,
379381
findNode,
382+
nodeLookup.value,
380383
)
381384

382385
const isOwnHandle = result.connection?.source === result.connection?.target

packages/core/src/utils/handle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export function getClosestHandle(
9595
const { x, y } = getHandlePosition(node, handle, handle.position, true)
9696

9797
const distance = Math.sqrt((x - position.x) ** 2 + (y - position.y) ** 2)
98+
9899
if (distance > connectionRadius) {
99100
continue
100101
}
@@ -139,6 +140,7 @@ export function isValidHandle(
139140
edges: GraphEdge[],
140141
nodes: GraphNode[],
141142
findNode: Actions['findNode'],
143+
nodeLookup: NodeLookup,
142144
) {
143145
const isTarget = fromType === 'target'
144146
const handleDomNode = handle
@@ -195,7 +197,7 @@ export function isValidHandle(
195197
targetNode: findNode(connection.target)!,
196198
})
197199

198-
result.toHandle = handle
200+
result.toHandle = getHandle(handleNodeId, handleType, handleId, nodeLookup, connectionMode, true)
199201
}
200202

201203
return result

0 commit comments

Comments
 (0)