Skip to content

Commit 490473d

Browse files
committed
fix(core): prevent multi touch from aborting connections (#1938)
* fix(core): prevent multi touch from aborting connections Signed-off-by: braks <[email protected]> * chore(changeset): add --------- Signed-off-by: braks <[email protected]>
1 parent c9c26d0 commit 490473d

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

.changeset/selfish-geese-attack.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+
Prevent multi touch from aborting connections.

packages/core/src/composables/useHandle.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ export function useHandle({
278278
}
279279

280280
function onPointerUp(event: MouseTouchEvent) {
281+
// Prevent multi-touch aborting connection
282+
if ('touches' in event && event.touches.length > 0) {
283+
return
284+
}
285+
281286
if ((closestHandle || handleDomNode) && connection && isValid) {
282287
if (!onEdgeUpdate) {
283288
emits.connect(connection)

packages/core/src/container/Viewport/Viewport.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ const shouldPanOnScroll = toRef(() => panKeyPressed.value || panOnScroll.value)
7676
7777
const isSelecting = toRef(() => selectionKeyPressed.value || (selectionKeyCode.value === true && shouldPanOnDrag.value !== true))
7878
79+
const connectionInProgress = toRef(() => connectionStartHandle.value !== null)
80+
7981
onMounted(() => {
8082
if (!viewportRef.value) {
8183
warn('Viewport element is missing')
@@ -163,6 +165,7 @@ onMounted(() => {
163165
const zoomScroll = zoomKeyPressed.value || zoomOnScroll.value
164166
const pinchZoom = zoomOnPinch.value && event.ctrlKey
165167
const eventButton = (event as MouseEvent).button
168+
const isWheelEvent = event.type === 'wheel'
166169
167170
if (
168171
eventButton === 1 &&
@@ -182,30 +185,35 @@ onMounted(() => {
182185
return false
183186
}
184187
188+
// we want to disable pinch-zooming while making a connection
189+
if (connectionInProgress.value && !isWheelEvent) {
190+
return false
191+
}
192+
185193
// if zoom on double click is disabled, we prevent the double click event
186194
if (!zoomOnDoubleClick.value && event.type === 'dblclick') {
187195
return false
188196
}
189197
190198
// if the target element is inside an element with the nowheel class, we prevent zooming
191-
if (isWrappedWithClass(event, noWheelClassName.value) && event.type === 'wheel') {
199+
if (isWrappedWithClass(event, noWheelClassName.value) && isWheelEvent) {
192200
return false
193201
}
194202
195203
// if the target element is inside an element with the nopan class, we prevent panning
196204
if (
197205
isWrappedWithClass(event, noPanClassName.value) &&
198-
(event.type !== 'wheel' || (shouldPanOnScroll.value && event.type === 'wheel' && !zoomKeyPressed.value))
206+
(!isWheelEvent || (shouldPanOnScroll.value && isWheelEvent && !zoomKeyPressed.value))
199207
) {
200208
return false
201209
}
202210
203-
if (!zoomOnPinch.value && event.ctrlKey && event.type === 'wheel') {
211+
if (!zoomOnPinch.value && event.ctrlKey && isWheelEvent) {
204212
return false
205213
}
206214
207215
// when there is no scroll handling enabled, we prevent all wheel events
208-
if (!zoomScroll && !shouldPanOnScroll.value && !pinchZoom && event.type === 'wheel') {
216+
if (!zoomScroll && !shouldPanOnScroll.value && !pinchZoom && isWheelEvent) {
209217
return false
210218
}
211219
@@ -242,7 +250,7 @@ onMounted(() => {
242250
eventButton <= 1
243251
244252
// default filter for d3-zoom
245-
return (!event.ctrlKey || panKeyPressed.value || event.type === 'wheel') && buttonAllowed
253+
return (!event.ctrlKey || panKeyPressed.value || isWheelEvent) && buttonAllowed
246254
})
247255
248256
watch(
@@ -414,7 +422,7 @@ export default {
414422
:is-selecting="isSelecting"
415423
:selection-key-pressed="selectionKeyPressed"
416424
:class="{
417-
connecting: !!connectionStartHandle,
425+
connecting: connectionInProgress,
418426
dragging: paneDragging,
419427
draggable: panOnDrag === true || (Array.isArray(panOnDrag) && panOnDrag.includes(0)),
420428
}"

0 commit comments

Comments
 (0)