diff --git a/src/web/tools/PointerEventManager.ts b/src/web/tools/PointerEventManager.ts index 2168752b6d..9cc4e91206 100644 --- a/src/web/tools/PointerEventManager.ts +++ b/src/web/tools/PointerEventManager.ts @@ -83,11 +83,27 @@ export default class PointerEventManager extends EventManager { } }); + const lastPosition: { x: number | null; y: number | null } = { + x: null, + y: null, + }; + this.view.addEventListener('pointermove', (event: PointerEvent): void => { if (event.pointerType === PointerType.TOUCH) { return; } + // Stylus triggers `pointermove` event when it detects changes in pressure. Since it is very sensitive to those changes, + // it constantly sends events, even though there was no change in position. To fix that we check whether + // pointer has actually moved and if not, we do not send event. + if ( + event.pointerType === PointerType.PEN && + event.x === lastPosition.x && + event.y === lastPosition.y + ) { + return; + } + const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.MOVE); const target = event.target as HTMLElement; @@ -136,6 +152,9 @@ export default class PointerEventManager extends EventManager { this.onPointerOutOfBounds(adaptedEvent); } } + + lastPosition.x = event.x; + lastPosition.y = event.y; }); this.view.addEventListener('pointercancel', (event: PointerEvent): void => {