@@ -236,6 +236,23 @@ export const SelectionHandler = (
236236 } ) ;
237237 }
238238
239+ const onKeyup = ( evt : KeyboardEvent ) => {
240+ if ( evt . key === 'Shift' && currentTarget ) {
241+ // Proper lifecycle management: clear selection first...
242+ selection . clear ( ) ;
243+
244+ // ...then add annotation to store...
245+ store . addAnnotation ( {
246+ id : currentTarget . annotation ,
247+ bodies : [ ] ,
248+ target : currentTarget
249+ } ) ;
250+
251+ // ...then make the new annotation the current selection
252+ selection . userSelect ( currentTarget . annotation , cloneKeyboardEvent ( evt ) ) ;
253+ }
254+ }
255+
239256 hotkeys ( SELECTION_KEYS . join ( ',' ) , { element : container , keydown : true , keyup : false } , ( evt ) => {
240257 if ( ! evt . repeat )
241258 lastDownEvent = cloneKeyboardEvent ( evt ) ;
@@ -267,6 +284,7 @@ export const SelectionHandler = (
267284 document . addEventListener ( 'pointerup' , onPointerUp ) ;
268285
269286 if ( annotatingEnabled ) {
287+ container . addEventListener ( 'keyup' , onKeyup ) ;
270288 container . addEventListener ( 'selectstart' , onSelectStart ) ;
271289 document . addEventListener ( 'selectionchange' , onSelectionChange ) ;
272290 }
@@ -275,6 +293,7 @@ export const SelectionHandler = (
275293 container . removeEventListener ( 'pointerdown' , onPointerDown ) ;
276294 document . removeEventListener ( 'pointerup' , onPointerUp ) ;
277295
296+ container . removeEventListener ( 'keyup' , onKeyup ) ;
278297 container . removeEventListener ( 'selectstart' , onSelectStart ) ;
279298 document . removeEventListener ( 'selectionchange' , onSelectionChange ) ;
280299
0 commit comments