Merge pull request #16561 from calixteman/editor_copy_existing
[Editor] Avoid an exception when copying an existing editor
This commit is contained in:
commit
46b8f9e2f2
@ -493,8 +493,9 @@ class AnnotationEditor {
|
|||||||
* new annotation to add to the pdf document.
|
* new annotation to add to the pdf document.
|
||||||
*
|
*
|
||||||
* To implement in subclasses.
|
* To implement in subclasses.
|
||||||
|
* @param {boolean} isForCopying
|
||||||
*/
|
*/
|
||||||
serialize() {
|
serialize(_isForCopying = false) {
|
||||||
unreachable("An editor must be serializable");
|
unreachable("An editor must be serializable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
serialize() {
|
serialize(isForCopying = false) {
|
||||||
if (this.isEmpty()) {
|
if (this.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -596,13 +596,20 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
pageIndex: this.pageIndex,
|
pageIndex: this.pageIndex,
|
||||||
rect,
|
rect,
|
||||||
rotation: this.rotation,
|
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)) {
|
if (this.annotationElementId && !this.#hasElementChanged(serialized)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serialized.id = this.annotationElementId;
|
||||||
|
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,11 +555,8 @@ class AnnotationEditorUIManager {
|
|||||||
|
|
||||||
const editors = [];
|
const editors = [];
|
||||||
for (const editor of this.#selectedEditors) {
|
for (const editor of this.#selectedEditors) {
|
||||||
if (!editor.isEmpty()) {
|
const serialized = editor.serialize(/* isForCopying = */ true);
|
||||||
const serialized = editor.serialize();
|
if (serialized) {
|
||||||
// Remove the id from the serialized data because it mustn't be linked
|
|
||||||
// to an existing annotation.
|
|
||||||
delete serialized.id;
|
|
||||||
editors.push(serialized);
|
editors.push(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1082,4 +1082,38 @@ describe("FreeText Editor", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("FreeText (copy/paste existing)", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
pages = await loadAndWait("freetexts.pdf", ".annotationEditorLayer");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must copy and paste an existing annotation", async () => {
|
||||||
|
// Run sequentially to avoid clipboard issues.
|
||||||
|
for (const [browserName, page] of pages) {
|
||||||
|
await page.click("#editorFreeText");
|
||||||
|
|
||||||
|
const editorIds = await getEditors(page, "freeText");
|
||||||
|
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(6);
|
||||||
|
|
||||||
|
const editorRect = await page.$eval(getEditorSelector(1), el => {
|
||||||
|
const { x, y, width, height } = el.getBoundingClientRect();
|
||||||
|
return { x, y, width, height };
|
||||||
|
});
|
||||||
|
await page.mouse.click(
|
||||||
|
editorRect.x + editorRect.width / 2,
|
||||||
|
editorRect.y + editorRect.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
await copyPaste(page);
|
||||||
|
await waitForStorageEntries(page, 7);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user