Skip to content

Commit

Permalink
fix(OrbitControls): make use of setPointerCapture (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryUlyanov authored Sep 28, 2023
1 parent 9753e6b commit 347c19c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/controls/OrbitControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ class OrbitControls extends EventDispatcher {
scope.domElement?.removeEventListener('pointerdown', onPointerDown)
scope.domElement?.removeEventListener('pointercancel', onPointerCancel)
scope.domElement?.removeEventListener('wheel', onMouseWheel)
scope.domElement?.ownerDocument.removeEventListener('pointermove', onPointerMove)
scope.domElement?.ownerDocument.removeEventListener('pointerup', onPointerUp)
scope.domElement?.removeEventListener('pointermove', onPointerMove)
scope.domElement?.removeEventListener('pointerup', onPointerUp)
if (scope._domElementKeyEvents !== null) {
scope._domElementKeyEvents.removeEventListener('keydown', onKeyDown)
}
Expand Down Expand Up @@ -812,8 +812,10 @@ class OrbitControls extends EventDispatcher {
if (scope.enabled === false) return

if (pointers.length === 0) {
scope.domElement?.ownerDocument.addEventListener('pointermove', onPointerMove)
scope.domElement?.ownerDocument.addEventListener('pointerup', onPointerUp)
scope.domElement?.setPointerCapture(event.pointerId)

scope.domElement?.addEventListener('pointermove', onPointerMove)
scope.domElement?.addEventListener('pointerup', onPointerUp)
}

addPointer(event)
Expand Down Expand Up @@ -841,8 +843,8 @@ class OrbitControls extends EventDispatcher {
if (pointers.length === 0) {
scope.domElement?.releasePointerCapture(event.pointerId)

scope.domElement?.ownerDocument.removeEventListener('pointermove', onPointerMove)
scope.domElement?.ownerDocument.removeEventListener('pointerup', onPointerUp)
scope.domElement?.removeEventListener('pointermove', onPointerMove)
scope.domElement?.removeEventListener('pointerup', onPointerUp)
}

scope.dispatchEvent(endEvent)
Expand Down

0 comments on commit 347c19c

Please sign in to comment.