Skip to content

Commit 763f107

Browse files
committed
fix(core): prevent calling selectionEnd on selection click (#1545)
* fix(core): prevent calling `selectionEnd` on selection click * chore(changeset): add
1 parent f329831 commit 763f107

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

.changeset/silly-days-sniff.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 calling `onSelectionEnd` when clicking a selection

packages/core/src/container/Pane/Pane.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const edgeIdLookup = ref<Map<string, Set<string>>>(new Map())
4646
const hasActiveSelection = toRef(() => elementsSelectable.value && (isSelecting || userSelectionActive.value))
4747
4848
// Used to prevent click events when the user lets go of the selectionKey during a selection
49-
const selectionInProgress = ref(false)
49+
let selectionInProgress = false
50+
let selectionStarted = false
5051
5152
const deleteKeyPressed = useKeyPress(deleteKeyCode, { actInsideInputWithModifier: false })
5253
@@ -87,8 +88,8 @@ function resetUserSelection() {
8788
}
8889
8990
function onClick(event: MouseEvent) {
90-
if (selectionInProgress.value) {
91-
selectionInProgress.value = false
91+
if (selectionInProgress) {
92+
selectionInProgress = false
9293
return
9394
}
9495
@@ -128,6 +129,8 @@ function onPointerDown(event: PointerEvent) {
128129
129130
const { x, y } = getMousePosition(event, containerBounds.value)
130131
132+
selectionStarted = true
133+
selectionInProgress = false
131134
edgeIdLookup.value = new Map()
132135
133136
for (const [id, edge] of edgeLookup.value) {
@@ -157,7 +160,7 @@ function onPointerMove(event: PointerEvent) {
157160
return
158161
}
159162
160-
selectionInProgress.value = true
163+
selectionInProgress = true
161164
162165
const { x: mouseX, y: mouseY } = getEventPosition(event, containerBounds.value)
163166
const { startX = 0, startY = 0 } = userSelectionRect.value
@@ -212,7 +215,7 @@ function onPointerMove(event: PointerEvent) {
212215
}
213216
214217
function onPointerUp(event: PointerEvent) {
215-
if (event.button !== 0) {
218+
if (event.button !== 0 || !selectionStarted) {
216219
return
217220
}
218221
@@ -235,8 +238,10 @@ function onPointerUp(event: PointerEvent) {
235238
// If the user kept holding the selectionKey during the selection,
236239
// we need to reset the selectionInProgress, so the next click event is not prevented
237240
if (selectionKeyPressed) {
238-
selectionInProgress.value = false
241+
selectionInProgress = false
239242
}
243+
244+
selectionStarted = false
240245
}
241246
</script>
242247

0 commit comments

Comments
 (0)