Skip to content

Commit bd7576d

Browse files
committed
Update annotation-plugin.ts
1 parent 1f551ef commit bd7576d

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

packages/plugin-annotation/src/lib/annotation-plugin.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ export class AnnotationPlugin extends BasePlugin<
477477
tool: this.getActiveTool(documentId),
478478
});
479479
}
480+
481+
// Update page activity when selection changes
482+
if (prevDoc?.selectedUids !== nextDoc.selectedUids) {
483+
this.updateAnnotationSelectionActivity(documentId, nextDoc);
484+
}
480485
}
481486
}
482487

@@ -954,16 +959,35 @@ export class AnnotationPlugin extends BasePlugin<
954959
this.dispatch(selectAnnotation(docId, pageIndex, id));
955960
}
956961

957-
// Claim page activity so the scroll plugin can elevate this page
958-
this.interactionManager?.claimPageActivity(docId, 'annotation-selection', pageIndex);
962+
// Page activity is managed centrally in onStoreUpdated via updateAnnotationSelectionActivity
959963
}
960964

961965
private deselectAnnotation(documentId?: string) {
962966
const docId = documentId ?? this.getActiveDocumentId();
963967
this.dispatch(deselectAnnotation(docId));
968+
// Page activity is managed centrally in onStoreUpdated via updateAnnotationSelectionActivity
969+
}
964970

965-
// Release page activity claim
966-
this.interactionManager?.releasePageActivity(docId, 'annotation-selection');
971+
/**
972+
* Derive page activity from the current annotation selection.
973+
* Called from onStoreUpdated whenever selectedUids changes,
974+
* so ALL selection code paths are covered automatically.
975+
*/
976+
private updateAnnotationSelectionActivity(docId: string, docState: AnnotationDocumentState) {
977+
if (docState.selectedUids.length === 0) {
978+
this.interactionManager?.releasePageActivity(docId, 'annotation-selection');
979+
return;
980+
}
981+
// Claim for the page of the first selected annotation
982+
const firstUid = docState.selectedUids[0];
983+
const ta = docState.byUid[firstUid];
984+
if (ta) {
985+
this.interactionManager?.claimPageActivity(
986+
docId,
987+
'annotation-selection',
988+
ta.object.pageIndex,
989+
);
990+
}
967991
}
968992

969993
// ─────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)