Skip to content

Commit

Permalink
Added pointer events listeners to the global scope
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Aug 13, 2024
1 parent e6d3f33 commit e492c82
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit e492c82

Please sign in to comment.