Skip to content

Commit

Permalink
fix(events): fix triggering panzoomend for one pointer event
Browse files Browse the repository at this point in the history
Fixes gh-428
  • Loading branch information
timmywil committed Nov 22, 2019
1 parent 7c9d819 commit f23e0fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/panzoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,18 @@ function Panzoom(
}

function handleUp(event: PointerEvent) {
// Don't call panzoomend when panning with 2 touches
// until both touches end
if (pointers.length === 1) {
trigger('panzoomend', { x, y, scale }, options)
}
// Note: don't remove all pointers
// Can restart without having to reinitiate all of them
// Remove the pointer regardless of the isPanning state
removePointer(pointers, event)
if (!isPanning) {
return
}
// Only call panzoomend once
if (pointers.length === 1) {
trigger('panzoomend', { x, y, scale }, options)
}
isPanning = false
origX = origY = startClientX = startClientY = undefined
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/panzoom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ describe('Panzoom', () => {
}
const panzoom = Panzoom(div)
assert(Object.keys(events).length > 0)
const endListener = () => {
console.log('panzoomend called')
assert.ok('panzoomend called on pan')
}
div.addEventListener('panzoomend', endListener)
div.dispatchEvent(new PointerEvent('pointerdown'))
document.dispatchEvent(new PointerEvent('pointerup'))
panzoom.destroy()
div.removeEventListener('panzoomend', endListener)
assert(Object.keys(events).length === 0)
Element.prototype.addEventListener = addEvent
Element.prototype.removeEventListener = removeEvent
document.body.removeChild(div)
})
it('sets the expected transform-origin on SVG', () => {
const elem = document.createElementNS('http://www.w3.org/2000/svg', 'g')
Expand Down

0 comments on commit f23e0fa

Please sign in to comment.