Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,44 +327,45 @@ class Page {
async #replaceIdByRef(annotations, deletedAnnotations, existingAnnotations) {
const promises = [];
for (const annotation of annotations) {
if (annotation.id) {
const ref = Ref.fromString(annotation.id);
if (!ref) {
warn(`A non-linked annotation cannot be modified: ${annotation.id}`);
continue;
}
if (annotation.deleted) {
deletedAnnotations.put(ref, ref);
if (annotation.popupRef) {
const popupRef = Ref.fromString(annotation.popupRef);
if (popupRef) {
deletedAnnotations.put(popupRef, popupRef);
}
}
continue;
}
if (annotation.popup?.deleted) {
if (!annotation.id) {
continue;
}
const ref = Ref.fromString(annotation.id);
if (!ref) {
warn(`A non-linked annotation cannot be modified: ${annotation.id}`);
continue;
}
if (annotation.deleted) {
deletedAnnotations.put(ref);
if (annotation.popupRef) {
const popupRef = Ref.fromString(annotation.popupRef);
if (popupRef) {
deletedAnnotations.put(popupRef, popupRef);
deletedAnnotations.put(popupRef);
}
}
existingAnnotations?.put(ref);
annotation.ref = ref;
promises.push(
this.xref.fetchAsync(ref).then(
obj => {
if (obj instanceof Dict) {
annotation.oldAnnotation = obj.clone();
}
},
() => {
warn(`Cannot fetch \`oldAnnotation\` for: ${ref}.`);
}
)
);
delete annotation.id;
continue;
}
if (annotation.popup?.deleted) {
const popupRef = Ref.fromString(annotation.popupRef);
if (popupRef) {
deletedAnnotations.put(popupRef);
}
}
existingAnnotations?.put(ref);
annotation.ref = ref;
promises.push(
this.xref.fetchAsync(ref).then(
obj => {
if (obj instanceof Dict) {
annotation.oldAnnotation = obj.clone();
}
},
() => {
warn(`Cannot fetch \`oldAnnotation\` for: ${ref}.`);
}
)
);
delete annotation.id;
}
await Promise.all(promises);
}
Expand All @@ -375,7 +376,7 @@ class Page {
}
const partialEvaluator = this.#createPartialEvaluator(handler);

const deletedAnnotations = new RefMap();
const deletedAnnotations = new RefSet();
const existingAnnotations = new RefSet();
await this.#replaceIdByRef(
annotations,
Expand Down