Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): allow control key as pan activation key code #1707

Merged
merged 8 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-kiwis-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Allow Control key as pan activation key code.
5 changes: 5 additions & 0 deletions .changeset/plenty-timers-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Check `panOnDrag` for allowed drag buttons in d3 filter
5 changes: 5 additions & 0 deletions .changeset/serious-trains-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-flow/core": patch
---

Prevent browser context menu when triggering pane context menu event.
6 changes: 2 additions & 4 deletions packages/core/src/composables/useKeyPress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MaybeRefOrGetter } from 'vue'
import { onMounted, ref, toRef, toValue, watch } from 'vue'
import { ref, toRef, toValue, watch } from 'vue'
import type { KeyFilter, KeyPredicate } from '@vueuse/core'
import { onKeyStroke, useEventListener } from '@vueuse/core'

Expand Down Expand Up @@ -111,9 +111,7 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | boolean | nu
},
)

onMounted(() => {
useEventListener(window, ['blur', 'contextmenu'], reset)
})
useEventListener(['blur', 'contextmenu'], reset)

onKeyStroke(
(...args) => currentFilter(...args),
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/container/Pane/Pane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {
emits,
userSelectionActive,
removeSelectedElements,
panOnDrag,
userSelectionRect,
elementsSelectable,
nodesSelectionActive,
Expand Down Expand Up @@ -101,10 +100,8 @@ function onClick(event: MouseEvent) {
}

function onContextMenu(event: MouseEvent) {
if (Array.isArray(panOnDrag.value) && panOnDrag.value?.includes(2)) {
event.preventDefault()
return
}
event.preventDefault()
event.stopPropagation()

emits.paneContextMenu(event)
}
Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/container/Viewport/Viewport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ onMounted(() => {
const eventButton = (event as MouseEvent).button

if (
(shouldPanOnDrag.value === true || (Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(1))) &&
eventButton === 1 &&
event.type === 'mousedown' &&
((event.target as HTMLElement)?.closest('.vue-flow__node') || (event.target as HTMLElement)?.closest('.vue-flow__edge'))
(isWrappedWithClass(event, 'vue-flow__node') || isWrappedWithClass(event, 'vue-flow__edge'))
) {
return true
}
Expand Down Expand Up @@ -228,22 +227,22 @@ onMounted(() => {

// if the pane is only movable using allowed clicks
if (
Array.isArray(shouldPanOnDrag.value) &&
!shouldPanOnDrag.value.includes(eventButton) &&
Array.isArray(panOnDrag.value) &&
!panOnDrag.value.includes(eventButton) &&
(event.type === 'mousedown' || event.type === 'touchstart')
) {
return false
}

// We only allow right clicks if pan on drag is set to right-click
const buttonAllowed =
(Array.isArray(shouldPanOnDrag.value) && shouldPanOnDrag.value.includes(eventButton)) ||
(selectionKeyCode.value === true && Array.isArray(shouldPanOnDrag.value) && !shouldPanOnDrag.value.includes(0)) ||
(Array.isArray(panOnDrag.value) && panOnDrag.value.includes(eventButton)) ||
(selectionKeyCode.value === true && Array.isArray(panOnDrag.value) && !panOnDrag.value.includes(0)) ||
!eventButton ||
eventButton <= 1

// default filter for d3-zoom
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed
return (!event.ctrlKey || panKeyPressed.value || event.type === 'wheel') && buttonAllowed
})

watch(
Expand Down Expand Up @@ -293,7 +292,7 @@ onMounted(() => {
const _isMacOs = isMacOs()

// macOS sets ctrlKey=true for pinch gesture on a trackpad
if (event.ctrlKey && zoomOnPinch.value && _isMacOs) {
if (!panKeyPressed.value && event.ctrlKey && zoomOnPinch.value && _isMacOs) {
const point = pointer(event)
const pinchDelta = wheelDelta(event)
const zoom = currentZoom * 2 ** pinchDelta
Expand Down
Loading