From ed63ccd0a1d0b176250c6e8dc4706d0d5ad9cb3e Mon Sep 17 00:00:00 2001 From: Oleksandr Danylchenko Date: Tue, 3 Sep 2024 21:34:13 +0300 Subject: [PATCH] Added ignoring `pointerdown` on `not-annotatable` --- packages/text-annotator/src/SelectionHandler.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/text-annotator/src/SelectionHandler.ts b/packages/text-annotator/src/SelectionHandler.ts index 50c7c912..8ae727c3 100644 --- a/packages/text-annotator/src/SelectionHandler.ts +++ b/packages/text-annotator/src/SelectionHandler.ts @@ -116,6 +116,9 @@ export const SelectionHandler = ( // Therefore, to prevent right-click selection, we need to listen // to the initial pointerdown event and remember the button const onPointerDown = (evt: PointerEvent) => { + const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR); + if (!annotatable) return; + // Note that the event itself can be ephemeral! const { target, timeStamp, offsetX, offsetY, type } = evt; lastPointerDown = { ...evt, target, timeStamp, offsetX, offsetY, type }; @@ -125,8 +128,7 @@ export const SelectionHandler = ( const onPointerUp = (evt: PointerEvent) => { const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR); - if (!annotatable || !isLeftClick) - return; + if (!annotatable || !isLeftClick) return; // Logic for selecting an existing annotation by clicking it const clickSelect = () => {