@@ -23,6 +23,7 @@ class AnnotationManager {
2323 this . _onSave = options . onSave ;
2424 this . _onDelete = options . onDelete ;
2525 this . _onChangeHistory = options . onChangeHistory ;
26+ this . _trashesAnnotations = options . trashesAnnotations ;
2627 this . _adjustTextAnnotationPosition = options . adjustTextAnnotationPosition ;
2728 this . render = ( ) => {
2829 options . onRender ( [ ...this . _annotations ] ) ;
@@ -601,8 +602,10 @@ class AnnotationManager {
601602 if ( annotation ) {
602603 annotation . dateModified = ( new Date ( ) ) . toISOString ( ) ;
603604 }
604- // Assign new id when undeleting to reduce sync conflicts
605- if ( ! prevAnnotation ) {
605+ // Assign new id when undeleting to reduce sync conflicts. Clients that
606+ // trash annotations keep the deleted one around, so undeleting restores
607+ // it in place and the id has to stay the same for the client to find it.
608+ if ( ! prevAnnotation && ! this . _trashesAnnotations ) {
606609 let newID = this . _generateObjectKey ( ) ;
607610 mapping . set ( annotation . id , newID ) ;
608611 annotation . id = newID ;
@@ -635,8 +638,10 @@ class AnnotationManager {
635638 if ( annotation ) {
636639 annotation . dateModified = ( new Date ( ) ) . toISOString ( ) ;
637640 }
638- // Assign new id when undeleting to reduce sync conflicts
639- if ( ! prevAnnotation ) {
641+ // Assign new id when undeleting to reduce sync conflicts. Clients that
642+ // trash annotations keep the deleted one around, so undeleting restores
643+ // it in place and the id has to stay the same for the client to find it.
644+ if ( ! prevAnnotation && ! this . _trashesAnnotations ) {
640645 let newID = this . _generateObjectKey ( ) ;
641646 mapping . set ( annotation . id , newID ) ;
642647 annotation . id = newID ;
@@ -654,6 +659,12 @@ class AnnotationManager {
654659 return true ;
655660 }
656661
662+ // Drops history points for annotations that have left the reader so
663+ // that erased annotations cannot be brought back.
664+ clearHistoryForAnnotations ( ids ) {
665+ this . _clearInterferingHistory ( ids ) ;
666+ }
667+
657668 _clearInterferingHistory ( affectedAnnotationIDs ) {
658669 for ( let i = this . _undoStack . length - 1 ; i >= 0 ; i -- ) {
659670 if ( affectedAnnotationIDs . some ( id => this . _undoStack [ i ] . annotations . has ( id ) ) ) {
0 commit comments