Skip to content

Commit 25990e4

Browse files
committed
[Editor] Add a sidebar allowing the user to navigate between the comments in a pdf (bug 1985567)
This implements what has been specified but it's still not done: we have to handle editing a comment or an annotation containing one.
1 parent 13ba311 commit 25990e4

File tree

12 files changed

+767
-8
lines changed

12 files changed

+767
-8
lines changed

l10n/en-US/viewer.ftl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ pdfjs-comment-floating-button =
328328
.title = Comment
329329
.aria-label = Comment
330330
pdfjs-comment-floating-button-label = Comment
331+
pdfjs-editor-comment-button =
332+
.title = Comment
333+
.aria-label = Comment
334+
pdfjs-editor-comment-button-label = Comment
331335
pdfjs-editor-signature-button =
332336
.title = Add signature
333337
pdfjs-editor-signature-button-label = Add signature
@@ -395,6 +399,23 @@ pdfjs-free-text2 =
395399
.aria-label = Text Editor
396400
.default-content = Start typing…
397401
402+
# Used to show how many comments are present in the pdf file.
403+
# Variables:
404+
# $count (Number) - the number of comments.
405+
pdfjs-editor-comments-sidebar-title =
406+
{ $count ->
407+
[one] Comment
408+
*[other] Comments
409+
}
410+
411+
pdfjs-editor-comments-sidebar-close-button =
412+
.title = Close the sidebar
413+
.aria-label = Close the sidebar
414+
pdfjs-editor-comments-sidebar-close-button-label = Close the sidebar
415+
416+
# Instructional copy to add a comment by selecting text or an annotations.
417+
pdfjs-editor-comments-sidebar-no-comments = Add a comment by selecting text or an annotation.
418+
398419
## Alt-text dialog
399420

400421
# Alternative text (alt text) helps when people can't see the image.

src/display/editor/tools.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ class AnnotationEditorUIManager {
585585

586586
#activeEditor = null;
587587

588+
#allEditableAnnotations = null;
589+
588590
#allEditors = new Map();
589591

590592
#allLayers = new Map();
@@ -663,6 +665,8 @@ class AnnotationEditorUIManager {
663665

664666
#showAllStates = null;
665667

668+
#pdfDocument = null;
669+
666670
#previousStates = {
667671
isEditing: false,
668672
isEmpty: true,
@@ -846,6 +850,7 @@ class AnnotationEditorUIManager {
846850
this.#altTextManager = altTextManager;
847851
this.#commentManager = commentManager;
848852
this.#signatureManager = signatureManager;
853+
this.#pdfDocument = pdfDocument;
849854
this._eventBus = eventBus;
850855
eventBus._on("editingaction", this.onEditingAction.bind(this), { signal });
851856
eventBus._on("pagechanging", this.onPageChanging.bind(this), { signal });
@@ -928,6 +933,7 @@ class AnnotationEditorUIManager {
928933
this.#floatingToolbar = null;
929934
this.#mainHighlightColorPicker?.destroy();
930935
this.#mainHighlightColorPicker = null;
936+
this.#allEditableAnnotations = null;
931937
if (this.#focusMainContainerTimeoutId) {
932938
clearTimeout(this.#focusMainContainerTimeoutId);
933939
this.#focusMainContainerTimeoutId = null;
@@ -937,6 +943,7 @@ class AnnotationEditorUIManager {
937943
this.#translationTimeoutId = null;
938944
}
939945
this._editorUndoBar?.destroy();
946+
this.#pdfDocument = null;
940947
}
941948

942949
combinedSignal(ac) {
@@ -1790,6 +1797,10 @@ class AnnotationEditorUIManager {
17901797
this.#updateModeCapability = Promise.withResolvers();
17911798
this.#currentDrawingSession?.commitOrRemove();
17921799

1800+
if (this.#mode === AnnotationEditorType.POPUP) {
1801+
this.#commentManager?.hideSidebar();
1802+
}
1803+
17931804
this.#mode = mode;
17941805
if (mode === AnnotationEditorType.NONE) {
17951806
this.setEditingState(false);
@@ -1800,9 +1811,18 @@ class AnnotationEditorUIManager {
18001811
this.#updateModeCapability.resolve();
18011812
return;
18021813
}
1814+
18031815
if (mode === AnnotationEditorType.SIGNATURE) {
18041816
await this.#signatureManager?.loadSignatures();
18051817
}
1818+
if (mode === AnnotationEditorType.POPUP) {
1819+
this.#allEditableAnnotations ||=
1820+
await this.#pdfDocument.getAnnotationsByType(
1821+
new Set(this.#editorTypes.map(editorClass => editorClass._editorType))
1822+
);
1823+
this.#commentManager?.showSidebar(this.#allEditableAnnotations);
1824+
}
1825+
18061826
this.setEditingState(true);
18071827
await this.#enableAll();
18081828
this.unselectAll();

src/shared/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const AnnotationEditorType = {
7575
HIGHLIGHT: 9,
7676
STAMP: 13,
7777
INK: 15,
78+
POPUP: 16,
7879
SIGNATURE: 101,
7980
COMMENT: 102,
8081
};

web/app.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,30 @@ const PDFViewerApplication = {
493493
: null;
494494
const commentManager =
495495
AppOptions.get("enableComment") && appConfig.editCommentDialog
496-
? new CommentManager(appConfig.editCommentDialog, overlayManager)
496+
? new CommentManager(
497+
appConfig.editCommentDialog,
498+
{
499+
sidebar:
500+
appConfig.annotationEditorParams?.editorCommentsSidebar || null,
501+
commentsList:
502+
appConfig.annotationEditorParams?.editorCommentsSidebarList ||
503+
null,
504+
commentCount:
505+
appConfig.annotationEditorParams?.editorCommentsSidebarCount ||
506+
null,
507+
sidebarTitle:
508+
appConfig.annotationEditorParams?.editorCommentsSidebarTitle ||
509+
null,
510+
closeButton:
511+
appConfig.annotationEditorParams
512+
?.editorCommentsSidebarCloseButton || null,
513+
commentToolbarButton:
514+
appConfig.toolbar?.editorCommentButton || null,
515+
},
516+
eventBus,
517+
linkService,
518+
overlayManager
519+
)
497520
: null;
498521

499522
const enableHWA = AppOptions.get("enableHWA"),
@@ -589,6 +612,10 @@ const PDFViewerApplication = {
589612
if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) {
590613
editorSignatureButton.parentElement.hidden = false;
591614
}
615+
const editorCommentButton = appConfig.toolbar?.editorCommentButton;
616+
if (editorCommentButton && AppOptions.get("enableComment")) {
617+
editorCommentButton.parentElement.hidden = false;
618+
}
592619
this.annotationEditorParams = new AnnotationEditorParams(
593620
appConfig.annotationEditorParams,
594621
eventBus

0 commit comments

Comments
 (0)