Skip to content

Commit f80654a

Browse files
authored
fix: Prevent image panning when drawing with stylus in mask editor (#7216)
## Summary Track pen pointer IDs to prevent touch events from triggering pan/zoom while drawing with a stylus (Apple Pencil, Surface Pen, Android stylus). fix #6549, #7135 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7216-fix-Prevent-image-panning-when-drawing-with-stylus-in-mask-editor-2c26d73d3650813a926bda40ae83832c) by [Unito](https://www.unito.io)
1 parent 795733b commit f80654a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/composables/maskeditor/usePanAndZoom.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,19 @@ export function usePanAndZoom() {
402402
}
403403
)
404404

405+
const addPenPointerId = (pointerId: number): void => {
406+
if (!penPointerIdList.value.includes(pointerId)) {
407+
penPointerIdList.value.push(pointerId)
408+
}
409+
}
410+
411+
const removePenPointerId = (pointerId: number): void => {
412+
const index = penPointerIdList.value.indexOf(pointerId)
413+
if (index !== -1) {
414+
penPointerIdList.value.splice(index, 1)
415+
}
416+
}
417+
405418
return {
406419
initializeCanvasPanZoom,
407420
handlePanStart,
@@ -411,6 +424,8 @@ export function usePanAndZoom() {
411424
handleTouchEnd,
412425
updateCursorPosition,
413426
zoom,
414-
invalidatePanZoom
427+
invalidatePanZoom,
428+
addPenPointerId,
429+
removePenPointerId
415430
}
416431
}

src/composables/maskeditor/useToolManager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export function useToolManager(
114114
event.preventDefault()
115115
if (event.pointerType === 'touch') return
116116

117+
if (event.pointerType === 'pen') {
118+
panZoom.addPenPointerId(event.pointerId)
119+
}
120+
117121
const isSpacePressed = keyboard.isKeyDown(' ')
118122

119123
if (event.buttons === 4 || (event.buttons === 1 && isSpacePressed)) {
@@ -207,6 +211,11 @@ export function useToolManager(
207211
const handlePointerUp = async (event: PointerEvent): Promise<void> => {
208212
store.isPanning = false
209213
store.brushVisible = true
214+
215+
if (event.pointerType === 'pen') {
216+
panZoom.removePenPointerId(event.pointerId)
217+
}
218+
210219
if (event.pointerType === 'touch') return
211220
updateCursor()
212221
store.isAdjustingBrush = false

0 commit comments

Comments
 (0)