Merge pull request #14884 from Snuffleupagus/fileattachmentannotation-event
Simplify the "fileattachmentannotation"-event handling a little bit
This commit is contained in:
commit
0a34b3bb81
@ -23,7 +23,6 @@ import {
|
||||
AnnotationType,
|
||||
assert,
|
||||
shadow,
|
||||
stringToPDFString,
|
||||
unreachable,
|
||||
Util,
|
||||
warn,
|
||||
@ -2296,7 +2295,6 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
|
||||
|
||||
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
|
||||
source: this,
|
||||
id: stringToPDFString(filename),
|
||||
filename,
|
||||
content,
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ class PDFAttachmentViewer extends BaseTreeViewer {
|
||||
|
||||
this.eventBus._on(
|
||||
"fileattachmentannotation",
|
||||
this._appendAttachment.bind(this)
|
||||
this.#appendAttachment.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
@ -140,27 +140,22 @@ class PDFAttachmentViewer extends BaseTreeViewer {
|
||||
|
||||
/**
|
||||
* Used to append FileAttachment annotations to the sidebar.
|
||||
* @private
|
||||
*/
|
||||
_appendAttachment({ id, filename, content }) {
|
||||
#appendAttachment({ filename, content }) {
|
||||
const renderedPromise = this._renderedCapability.promise;
|
||||
|
||||
renderedPromise.then(() => {
|
||||
if (renderedPromise !== this._renderedCapability.promise) {
|
||||
return; // The FileAttachment annotation belongs to a previous document.
|
||||
}
|
||||
let attachments = this._attachments;
|
||||
const attachments = this._attachments || Object.create(null);
|
||||
|
||||
if (!attachments) {
|
||||
attachments = Object.create(null);
|
||||
} else {
|
||||
for (const name in attachments) {
|
||||
if (id === name) {
|
||||
return; // Ignore the new attachment if it already exists.
|
||||
}
|
||||
for (const name in attachments) {
|
||||
if (filename === name) {
|
||||
return; // Ignore the new attachment if it already exists.
|
||||
}
|
||||
}
|
||||
attachments[id] = {
|
||||
attachments[filename] = {
|
||||
filename,
|
||||
content,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user