mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[Editor] Avoid an exception when copying an existing editor
This commit is contained in:
parent
bd46a934ec
commit
ca3e45755c
4 changed files with 47 additions and 8 deletions
|
@ -493,8 +493,9 @@ class AnnotationEditor {
|
|||
* new annotation to add to the pdf document.
|
||||
*
|
||||
* To implement in subclasses.
|
||||
* @param {boolean} isForCopying
|
||||
*/
|
||||
serialize() {
|
||||
serialize(_isForCopying = false) {
|
||||
unreachable("An editor must be serializable");
|
||||
}
|
||||
|
||||
|
|
|
@ -567,7 +567,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
serialize() {
|
||||
serialize(isForCopying = false) {
|
||||
if (this.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -596,13 +596,20 @@ class FreeTextEditor extends AnnotationEditor {
|
|||
pageIndex: this.pageIndex,
|
||||
rect,
|
||||
rotation: this.rotation,
|
||||
id: this.annotationElementId,
|
||||
};
|
||||
|
||||
if (isForCopying) {
|
||||
// Don't add the id when copying because the pasted editor mustn't be
|
||||
// linked to an existing annotation.
|
||||
return serialized;
|
||||
}
|
||||
|
||||
if (this.annotationElementId && !this.#hasElementChanged(serialized)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
serialized.id = this.annotationElementId;
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
|
|
@ -555,11 +555,8 @@ class AnnotationEditorUIManager {
|
|||
|
||||
const editors = [];
|
||||
for (const editor of this.#selectedEditors) {
|
||||
if (!editor.isEmpty()) {
|
||||
const serialized = editor.serialize();
|
||||
// Remove the id from the serialized data because it mustn't be linked
|
||||
// to an existing annotation.
|
||||
delete serialized.id;
|
||||
const serialized = editor.serialize(/* isForCopying = */ true);
|
||||
if (serialized) {
|
||||
editors.push(serialized);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue