Skip to content

Commit

Permalink
fix(core): if selection key code is true prevent pan on drag on left …
Browse files Browse the repository at this point in the history
…mouse btn (#1670)

* fix(core): if selection key code is true prevent pan on drag on left mouse btn

Signed-off-by: braks <[email protected]>

* chore(changeset): add

Signed-off-by: braks <[email protected]>

* fix(tests): correct viewport drag tests

Signed-off-by: braks <[email protected]>

---------

Signed-off-by: braks <[email protected]>
  • Loading branch information
bcakmakoglu authored Nov 1, 2024
1 parent 00cff79 commit 4bc7658
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-pans-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

if selection key code is true prevent pan on drag on left mouse btn
17 changes: 9 additions & 8 deletions packages/core/src/container/Viewport/Viewport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ onMounted(() => {
return false
}
// if selection key code is true and panOnDrag tries to use left mouse button we prevent it
if (selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && panOnDrag.value.includes(0) && eventButton === 0) {
return false
}
// if the pane is only movable using allowed clicks
if (
Array.isArray(shouldPanOnDrag.value) &&
Expand All @@ -230,16 +235,12 @@ onMounted(() => {
return false
}
const leftMouseBtnPanAllowed =
eventButton !== 0 || (selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && !panOnDrag.value.includes(0))
// We only allow right clicks if pan on drag is set to right-click
const buttonAllowed =
leftMouseBtnPanAllowed &&
((Array.isArray(panOnDrag.value) && panOnDrag.value.includes(eventButton)) ||
(selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && !panOnDrag.value.includes(0)) ||
!eventButton ||
eventButton <= 1)
(Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(eventButton)) ||
(selectionKeyCode.value === true && Array.isArray(shouldPanOnDrag.value) && !shouldPanOnDrag.value.includes(0)) ||
!eventButton ||
eventButton <= 1
// default filter for d3-zoom
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('Viewport drag / zoom', () => {
beforeEach(() => {
cy.vueFlow({
nodes,
fitViewOnInit: false,
})
})

Expand All @@ -27,6 +28,7 @@ describe('Viewport drag / zoom', () => {
await cy.tryAssertion(() => {
cy.transformationPane()
.should('exist')
.should('not.have.css', 'transform', 'matrix(1, 0, 0, 1, 0, 0)')
.should(
'have.css',
'transform',
Expand Down

0 comments on commit 4bc7658

Please sign in to comment.