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