From e492c82f056aa1aaec11fec9d974873e555fab07 Mon Sep 17 00:00:00 2001 From: Oleksandr Danylchenko Date: Tue, 13 Aug 2024 19:50:51 +0300 Subject: [PATCH] Added pointer events listeners to the global scope --- packages/text-annotator/src/SelectionHandler.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/text-annotator/src/SelectionHandler.ts b/packages/text-annotator/src/SelectionHandler.ts index eedef19e..6f0df65d 100644 --- a/packages/text-annotator/src/SelectionHandler.ts +++ b/packages/text-annotator/src/SelectionHandler.ts @@ -124,7 +124,7 @@ export const SelectionHandler = ( isLeftClick = evt.button === 0; } - container.addEventListener('pointerdown', onPointerDown); + document.addEventListener('pointerdown', onPointerDown); const onPointerUp = (evt: PointerEvent) => { const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR); @@ -135,7 +135,11 @@ export const SelectionHandler = ( const clickSelect = () => { const { x, y } = container.getBoundingClientRect(); - const hovered = store.getAt(evt.clientX - x, evt.clientY - y, currentFilter); + const hovered = + evt.target instanceof Node && + container.contains(evt.target) && + store.getAt(evt.clientX - x, evt.clientY - y, currentFilter); + if (hovered) { const { selected } = selection; @@ -163,7 +167,7 @@ export const SelectionHandler = ( container.removeEventListener('selectstart', onSelectStart); document.removeEventListener('selectionchange', onSelectionChange); - container.removeEventListener('pointerdown', onPointerDown); + document.removeEventListener('pointerdown', onPointerDown); document.removeEventListener('pointerup', onPointerUp); }