Skip to content

Commit

Permalink
Merge branch 'recogito#136-fix-not-dismisssed-annotation-on-native-ra…
Browse files Browse the repository at this point in the history
…nge-click' into staging

# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
  • Loading branch information
oleksandr-danylchenko committed Aug 14, 2024
2 parents c26f15f + e7928f4 commit eb6342a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,26 @@ export const createSelectionHandler = (

const timeDifference = evt.timeStamp - lastDownEvent.timeStamp;

// Just a click, not a selection
if (document.getSelection().isCollapsed && timeDifference < 300) {
currentTarget = undefined;
userSelect();
} else if (currentTarget) {
selection.userSelect(currentTarget.annotation, evt);
}
/**
* We must check the `isCollapsed` within the 0-timeout
* to handle the annotation dismissal after a click properly.
*
* Otherwise, the `isCollapsed` will return an obsolete `false` value,
* click won't be processed, and the annotation will get falsely re-selected.
*
* @see https://github.com/recogito/text-annotator-js/issues/136
*/
setTimeout(() => {
const { isCollapsed } = document.getSelection()

// Just a click, not a selection
if (isCollapsed && timeDifference < 300) {
currentTarget = undefined;
userSelect();
} else if (currentTarget) {
selection.userSelect(currentTarget.annotation, evt);
}
});
}
document.addEventListener('pointerup', onPointerUp);

Expand Down

0 comments on commit eb6342a

Please sign in to comment.