Skip to content

Commit a045434

Browse files
Added isNotAnnotatable usage
1 parent a552780 commit a045434

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

packages/text-annotator/src/SelectionHandler.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
isMac,
1414
isWhitespaceOrEmpty,
1515
trimRangeToContainer,
16-
NOT_ANNOTATABLE_SELECTOR
16+
isNotAnnotatable
1717
} from './utils';
1818

1919
const CLICK_TIMEOUT = 300;
@@ -64,13 +64,14 @@ export const SelectionHandler = (
6464
* be annotatable (like a component popup).
6565
* Note that Chrome/iOS will sometimes return the root doc as target!
6666
*/
67-
const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
68-
currentTarget = annotatable ? {
69-
annotation: uuidv4(),
70-
selector: [],
71-
creator: currentUser,
72-
created: new Date()
73-
} : undefined;
67+
currentTarget = isNotAnnotatable(evt.target as Node)
68+
? undefined
69+
: {
70+
annotation: uuidv4(),
71+
selector: [],
72+
creator: currentUser,
73+
created: new Date()
74+
};
7475
};
7576

7677
const onSelectionChange = debounce((evt: Event) => {
@@ -79,8 +80,7 @@ export const SelectionHandler = (
7980
// This is to handle cases where the selection is "hijacked" by another element
8081
// in a not-annotatable area. A rare case in theory. But rich text editors
8182
// will like Quill do it...
82-
const annotatable = !sel.anchorNode?.parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
83-
if (!annotatable) {
83+
if (isNotAnnotatable(sel.anchorNode)) {
8484
currentTarget = undefined;
8585
return;
8686
}
@@ -163,8 +163,7 @@ export const SelectionHandler = (
163163
const onPointerDown = (evt: PointerEvent) => {
164164
if (isContextMenuOpen) return;
165165

166-
const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
167-
if (!annotatable) return;
166+
if (isNotAnnotatable(evt.target as Node)) return;
168167

169168
/**
170169
* Cloning the event to prevent it from accidentally being `undefined`
@@ -191,8 +190,7 @@ export const SelectionHandler = (
191190
const onPointerUp = (evt: PointerEvent) => {
192191
if (isContextMenuOpen) return;
193192

194-
const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
195-
if (!annotatable || !isLeftClick) return;
193+
if (isNotAnnotatable(evt.target as Node) || !isLeftClick) return;
196194

197195
// Logic for selecting an existing annotation
198196
const clickSelect = () => {

0 commit comments

Comments
 (0)