Skip to content

Commit

Permalink
Merge branch 'recogito#133-fix-not-dismissed-annotation-on-outside-cl…
Browse files Browse the repository at this point in the history
…ick' into staging

# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
  • Loading branch information
oleksandr-danylchenko committed Sep 4, 2024
2 parents bce7af8 + ed63ccd commit 31cd399
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
27 changes: 7 additions & 20 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ export const createSelectionHandler = (
* 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;

/**
* Cloning the event to prevent it from accidentally being `undefined`
* @see https://github.com/recogito/text-annotator-js/commit/65d13f3108c429311cf8c2523f6babbbc946013d#r144033948
Expand All @@ -182,11 +185,8 @@ export const createSelectionHandler = (
};

const onPointerUp = (evt: PointerEvent) => {
const evtTarget = evt.target as Node;

const annotatable = !evtTarget.parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
if (!annotatable || !isLeftClick)
return;
const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
if (!annotatable || !isLeftClick) return;

// Logic for selecting an existing annotation
const userSelect = () => {
Expand Down Expand Up @@ -223,21 +223,8 @@ export const createSelectionHandler = (

// Just a click, not a selection
if (sel?.isCollapsed && timeDifference < CLICK_TIMEOUT) {

/**
* Don't process the collapsed range as the click
* when it ends on the document root element, `html`.
*
* It can happen when user quickly drags from the
* `input`/`textarea` to the browser's toolbar.
*
* @see https://github.com/recogito/text-annotator-js/issues/147
*/
if (evtTarget !== document.documentElement) {
currentTarget = undefined;
userSelect();
}

currentTarget = undefined;
userSelect();
} else if (currentTarget && store.getAnnotation(currentTarget.annotation)) {
selection.userSelect(currentTarget.annotation, evt);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/text-annotator/src/TextAnnotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const createTextAnnotator = <E extends unknown = TextAnnotation>(

const setPresenceProvider = (provider: PresenceProvider) => {
if (provider) {
highlightRenderer.setPainter(createPresencePainter(container, provider, opts.presence));
highlightRenderer.setPainter(createPresencePainter(provider, opts.presence));
provider.on('selectionChange', () => highlightRenderer.redraw());
}
};
Expand Down
3 changes: 2 additions & 1 deletion packages/text-annotator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from './api';
export * from './highlight';
export * from './model';
export * from './state';
export * from './utils';
export * from './presence/PresencePainterOptions';
export * from './presence';
export * from './SelectionHandler';
export * from './TextAnnotator';
export * from './TextAnnotatorOptions';
Expand Down
1 change: 0 additions & 1 deletion packages/text-annotator/src/presence/PresencePainter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const createCanvas = () => {
}

export const createPresencePainter = (
container: HTMLElement,
provider: PresenceProvider,
opts: PresencePainterOptions = {}
): HighlightPainter => {
Expand Down

0 comments on commit 31cd399

Please sign in to comment.