Skip to content

Commit

Permalink
Merge pull request #135 from oleksandr-danylchenko/#133-fix-not-dismi…
Browse files Browse the repository at this point in the history
…ssed-annotation-on-outside-click

#133 Fixed missing annotation dismissal clicking outside of the annotator `container`
  • Loading branch information
rsimon authored Aug 30, 2024
2 parents 58fe247 + 2040cee commit dbb6e3c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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 @@ -140,7 +140,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 All @@ -166,9 +170,8 @@ export const SelectionHandler = (

const destroy = () => {
container.removeEventListener('selectstart', onSelectStart);
document.removeEventListener('selectionchange', onSelectionChange);

container.removeEventListener('pointerdown', onPointerDown);
document.removeEventListener('selectionchange', onSelectionChange);
document.removeEventListener('pointerdown', onPointerDown);
document.removeEventListener('pointerup', onPointerUp);
}

Expand Down

0 comments on commit dbb6e3c

Please sign in to comment.