@@ -169,20 +169,6 @@ export const SelectionHandler = (
169169 isLeftClick = lastDownEvent . button === 0 ;
170170 } ;
171171
172- // Helper
173- const upsertCurrentTarget = ( ) => {
174- const exists = store . getAnnotation ( currentTarget . annotation ) ;
175- if ( exists ) {
176- store . updateTarget ( currentTarget ) ;
177- } else {
178- store . addAnnotation ( {
179- id : currentTarget . annotation ,
180- bodies : [ ] ,
181- target : currentTarget
182- } ) ;
183- }
184- }
185-
186172 const onPointerUp = ( evt : PointerEvent ) => {
187173 if ( isNotAnnotatable ( evt . target as Node ) || ! isLeftClick ) return ;
188174
@@ -319,6 +305,29 @@ export const SelectionHandler = (
319305
320306 hotkeys ( ARROW_KEYS . join ( ',' ) , { keydown : true , keyup : false } , handleArrowKeyPress ) ;
321307
308+ // Helper
309+ const upsertCurrentTarget = ( ) => {
310+ const existingAnnotation = store . getAnnotation ( currentTarget . annotation ) ;
311+ if ( ! existingAnnotation ) {
312+ store . addAnnotation ( {
313+ id : currentTarget . annotation ,
314+ bodies : [ ] ,
315+ target : currentTarget
316+ } ) ;
317+ return ;
318+ }
319+
320+ const { target : { updated : existingTargetUpdated } } = existingAnnotation ;
321+ const { updated : currentTargetUpdated } = currentTarget ;
322+ if (
323+ ! existingAnnotation ||
324+ ! currentTargetUpdated ||
325+ existingTargetUpdated < currentTargetUpdated
326+ ) {
327+ store . updateTarget ( currentTarget ) ;
328+ }
329+ } ;
330+
322331 container . addEventListener ( 'pointerdown' , onPointerDown ) ;
323332 document . addEventListener ( 'pointerup' , onPointerUp ) ;
324333 document . addEventListener ( 'contextmenu' , onContextMenu ) ;
0 commit comments