fix(core): if selection key code is true prevent pan on drag on left mouse btn (#1670)
* fix(core): if selection key code is true prevent pan on drag on left mouse btn Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(changeset): add Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(tests): correct viewport drag tests Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@vue-flow/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
if selection key code is true prevent pan on drag on left mouse btn
|
||||||
@@ -221,6 +221,11 @@ onMounted(() => {
|
|||||||
return false
|
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 the pane is only movable using allowed clicks
|
||||||
if (
|
if (
|
||||||
Array.isArray(shouldPanOnDrag.value) &&
|
Array.isArray(shouldPanOnDrag.value) &&
|
||||||
@@ -230,16 +235,12 @@ onMounted(() => {
|
|||||||
return false
|
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
|
// We only allow right clicks if pan on drag is set to right-click
|
||||||
const buttonAllowed =
|
const buttonAllowed =
|
||||||
leftMouseBtnPanAllowed &&
|
(Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(eventButton)) ||
|
||||||
((Array.isArray(panOnDrag.value) && panOnDrag.value.includes(eventButton)) ||
|
(selectionKeyCode.value === true && Array.isArray(shouldPanOnDrag.value) && !shouldPanOnDrag.value.includes(0)) ||
|
||||||
(selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && !panOnDrag.value.includes(0)) ||
|
!eventButton ||
|
||||||
!eventButton ||
|
eventButton <= 1
|
||||||
eventButton <= 1)
|
|
||||||
|
|
||||||
// default filter for d3-zoom
|
// default filter for d3-zoom
|
||||||
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed
|
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed
|
||||||
|
|||||||
+2
@@ -8,6 +8,7 @@ describe('Viewport drag / zoom', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.vueFlow({
|
cy.vueFlow({
|
||||||
nodes,
|
nodes,
|
||||||
|
fitViewOnInit: false,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ describe('Viewport drag / zoom', () => {
|
|||||||
await cy.tryAssertion(() => {
|
await cy.tryAssertion(() => {
|
||||||
cy.transformationPane()
|
cy.transformationPane()
|
||||||
.should('exist')
|
.should('exist')
|
||||||
|
.should('not.have.css', 'transform', 'matrix(1, 0, 0, 1, 0, 0)')
|
||||||
.should(
|
.should(
|
||||||
'have.css',
|
'have.css',
|
||||||
'transform',
|
'transform',
|
||||||
Reference in New Issue
Block a user