Skip to content

Commit

Permalink
fix(pointer): check all fields of PointerCoords in `isDifferentPoin…
Browse files Browse the repository at this point in the history
…terPosition()` (#1229)

Co-authored-by: Bryan Jensen <[email protected]>
  • Loading branch information
bawjensen and bryan-codaio authored Jan 15, 2025
1 parent 75edef5 commit 5f3d28f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/system/pointer/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export function isDifferentPointerPosition(
positionA.target !== positionB.target ||
positionA.coords?.x !== positionB.coords?.x ||
positionA.coords?.y !== positionB.coords?.y ||
positionA.coords?.clientX !== positionB.coords?.clientX ||
positionA.coords?.clientY !== positionB.coords?.clientY ||
positionA.coords?.offsetX !== positionB.coords?.offsetX ||
positionA.coords?.offsetY !== positionB.coords?.offsetY ||
positionA.coords?.pageX !== positionB.coords?.pageX ||
positionA.coords?.pageY !== positionB.coords?.pageY ||
positionA.coords?.screenX !== positionB.coords?.screenX ||
positionA.coords?.screenY !== positionB.coords?.screenY ||
positionA.caret?.node !== positionB.caret?.node ||
positionA.caret?.offset !== positionB.caret?.offset
)
Expand Down
21 changes: 21 additions & 0 deletions tests/pointer/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ test('drag sequence', async () => {
`)
})

test('drag sequence w/ differing client coordinates', async () => {
const {element, getClickEventsSnapshot, user} = setup(`<div></div>`)

await user.pointer([
{keys: '[MouseLeft>]', target: element, coords: {clientX: 0, clientY: 0}},
{target: element, coords: {clientX: 0, clientY: 0}}, // doesn't actually move, won't show up in snapshot below
{target: element, coords: {clientX: 10, clientY: 0}}, // will show up in snapshot below
'[/MouseLeft]',
])

expect(getClickEventsSnapshot()).toMatchInlineSnapshot(`
pointerdown - pointerId=1; pointerType=mouse; isPrimary=true
mousedown - button=0; buttons=1; detail=1
pointermove - pointerId=1; pointerType=mouse; isPrimary=true
mousemove - button=0; buttons=1; detail=0
pointerup - pointerId=1; pointerType=mouse; isPrimary=true
mouseup - button=0; buttons=0; detail=1
click - button=0; buttons=0; detail=1
`)
})

test('drag touch', async () => {
const {element, getClickEventsSnapshot, user} = setup(`<div></div>`)

Expand Down

0 comments on commit 5f3d28f

Please sign in to comment.