1
1
import type { MaybeRefOrGetter } from 'vue'
2
2
import { toValue } from 'vue'
3
- import type { Connection , ConnectionHandle , HandleType , MouseTouchEvent , ValidConnectionFunc } from '../types'
3
+ import type { Connection , ConnectionHandle , HandleType , MouseTouchEvent , ValidConnectionFunc , ValidHandleResult } from '../types'
4
4
import {
5
5
calcAutoPan ,
6
6
getClosestHandle ,
@@ -71,6 +71,7 @@ export function useHandle({
71
71
let connection : Connection | null = null
72
72
let isValid = false
73
73
let handleDomNode : Element | null = null
74
+ let previousConnection : ValidHandleResult | null = null
74
75
75
76
function handlePointerDown ( event : MouseTouchEvent ) {
76
77
const isTarget = toValue ( type ) === 'target'
@@ -176,6 +177,20 @@ export function useHandle({
176
177
isValid = validHandleResult . isValid
177
178
handleDomNode = validHandleResult . handleDomNode
178
179
180
+ // we don't want to trigger an update when the connection
181
+ // is snapped to the same handle as before
182
+ if (
183
+ isValid &&
184
+ closestHandle &&
185
+ previousConnection ?. endHandle &&
186
+ validHandleResult . endHandle &&
187
+ previousConnection . endHandle . type === validHandleResult . endHandle . type &&
188
+ previousConnection . endHandle . nodeId === validHandleResult . endHandle . nodeId &&
189
+ previousConnection . endHandle . handleId === validHandleResult . endHandle . handleId
190
+ ) {
191
+ return
192
+ }
193
+
179
194
updateConnection (
180
195
closestHandle && isValid
181
196
? rendererPointToPoint (
@@ -190,6 +205,8 @@ export function useHandle({
190
205
getConnectionStatus ( ! ! closestHandle , isValid ) ,
191
206
)
192
207
208
+ previousConnection = validHandleResult
209
+
193
210
if ( ! closestHandle && ! isValid && ! handleDomNode ) {
194
211
return resetRecentHandle ( prevActiveHandle )
195
212
}
0 commit comments