Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#133 Fixed missing annotation dismissal clicking outside of the annotator container (vol.2) #149

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -171,7 +173,7 @@ export const SelectionHandler = (
});
}

container.addEventListener('pointerdown', onPointerDown);
document.addEventListener('pointerdown', onPointerDown);
document.addEventListener('pointerup', onPointerUp);

if (annotatingEnabled) {
Expand All @@ -180,7 +182,7 @@ export const SelectionHandler = (
}

const destroy = () => {
container.removeEventListener('pointerdown', onPointerDown);
document.removeEventListener('pointerdown', onPointerDown);
document.removeEventListener('pointerup', onPointerUp);

container.removeEventListener('selectstart', onSelectStart);
Expand Down