Skip to content

Commit 0d15b8b

Browse files
committed
Simplify the "fileattachmentannotation"-event handling a little bit
*This patch can be tested, in the viewer, using the `annotation-fileattachment.pdf` document from the test-suite.* Note how the `FileSpec`-implementation already uses `stringToPDFString` during the filename lookup, see https://github.com/mozilla/pdf.js/blob/cfac6fa511945ae5b75d3c27a9356527862a7bf6/src/core/file_spec.js#L70 Hence there's no reason to repeat that again in the `FileAttachmentAnnotationElement`-constructor, and we can thus simplify the "fileattachmentannotation"-event handling a little bit.
1 parent cfac6fa commit 0d15b8b

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/display/annotation_layer.js

-1
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,6 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
22962296

22972297
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
22982298
source: this,
2299-
id: stringToPDFString(filename),
23002299
filename,
23012300
content,
23022301
});

web/pdf_attachment_viewer.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PDFAttachmentViewer extends BaseTreeViewer {
3838

3939
this.eventBus._on(
4040
"fileattachmentannotation",
41-
this._appendAttachment.bind(this)
41+
this.#appendAttachment.bind(this)
4242
);
4343
}
4444

@@ -140,27 +140,22 @@ class PDFAttachmentViewer extends BaseTreeViewer {
140140

141141
/**
142142
* Used to append FileAttachment annotations to the sidebar.
143-
* @private
144143
*/
145-
_appendAttachment({ id, filename, content }) {
144+
#appendAttachment({ filename, content }) {
146145
const renderedPromise = this._renderedCapability.promise;
147146

148147
renderedPromise.then(() => {
149148
if (renderedPromise !== this._renderedCapability.promise) {
150149
return; // The FileAttachment annotation belongs to a previous document.
151150
}
152-
let attachments = this._attachments;
153-
154-
if (!attachments) {
155-
attachments = Object.create(null);
156-
} else {
157-
for (const name in attachments) {
158-
if (id === name) {
159-
return; // Ignore the new attachment if it already exists.
160-
}
151+
const attachments = this._attachments || Object.create(null);
152+
153+
for (const name in attachments) {
154+
if (filename === name) {
155+
return; // Ignore the new attachment if it already exists.
161156
}
162157
}
163-
attachments[id] = {
158+
attachments[filename] = {
164159
filename,
165160
content,
166161
};

0 commit comments

Comments
 (0)