Skip to content

Commit efa4b06

Browse files
committed
Skipping index insert in case the annotation has no DomRects
1 parent e1f30f9 commit efa4b06

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/text-annotator/src/state/spatialTree.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export const createSpatialTree = <T extends TextAnnotation>(store: Store<T>, con
6868

6969
const insert = (target: TextAnnotationTarget) => {
7070
const rects = toItems(target, container.getBoundingClientRect());
71+
if (rects.length === 0) return;
72+
7173
rects.forEach(rect => tree.insert(rect));
7274
index.set(target.annotation, rects);
7375
}
@@ -92,7 +94,10 @@ export const createSpatialTree = <T extends TextAnnotation>(store: Store<T>, con
9294
const offset = container.getBoundingClientRect();
9395

9496
const rectsByTarget = targets.map(target => ({ target, rects: toItems(target, offset) }));
95-
rectsByTarget.forEach(({ target, rects }) => index.set(target.annotation, rects));
97+
rectsByTarget.forEach(({ target, rects }) => {
98+
if (rects.length > 0)
99+
index.set(target.annotation, rects)
100+
});
96101

97102
const allRects = rectsByTarget.flatMap(({ rects }) => rects);
98103
tree.load(allRects);
@@ -144,7 +149,7 @@ export const createSpatialTree = <T extends TextAnnotation>(store: Store<T>, con
144149

145150
const getAnnotationRects = (id: string): DOMRect[] => {
146151
const indexed = index.get(id);
147-
if (indexed[0]) {
152+
if (indexed) {
148153
// Reminder: *each* IndexedHighlightRect stores *all*
149154
// DOMRects for the annotation for convenience
150155
return indexed[0].annotation.rects;

0 commit comments

Comments
 (0)