@@ -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