Skip to content

Commit

Permalink
[Editor] A pasted FreeText editor was missing when printing/saving
Browse files Browse the repository at this point in the history
When a FreeText editor is pasted then it hasn't an editorDiv yet when added
to the layer, hence it's empty.
So this patch just move the call to addToAnnotationStorage to ensure we've
what we need.
  • Loading branch information
calixteman committed Aug 4, 2022
1 parent b985eaa commit 96c712f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ class AnnotationEditorLayer {
*/
add(editor) {
this.#changeParent(editor);
this.addToAnnotationStorage(editor);
this.#uiManager.addEditor(editor);
this.attach(editor);

Expand All @@ -438,6 +437,7 @@ class AnnotationEditorLayer {

this.moveDivInDOM(editor);
editor.onceAdded();
this.addToAnnotationStorage(editor);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions test/integration/freetext_editor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe("Editor", () => {
await closePages(pages);
});

const countStorageEntries = async page =>
page.evaluate(
() =>
window.PDFViewerApplication.pdfDocument.annotationStorage._storage
.size
);

it("must write a string in a FreeText editor", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
Expand Down Expand Up @@ -64,6 +71,10 @@ describe("Editor", () => {
editorRect.y + 2 * editorRect.height
);

expect(await countStorageEntries(page))
.withContext(`In ${browserName}`)
.toEqual(1);

const content = await page.$eval(`${editorPrefix}0`, el =>
el.innerText.trimEnd()
);
Expand Down Expand Up @@ -94,6 +105,10 @@ describe("Editor", () => {
await page.keyboard.press("v");
await page.keyboard.up("Control");

expect(await countStorageEntries(page))
.withContext(`In ${browserName}`)
.toEqual(2);

const content = await page.$eval(`${editorPrefix}0`, el =>
el.innerText.trimEnd()
);
Expand All @@ -114,6 +129,10 @@ describe("Editor", () => {
await page.keyboard.press("v");
await page.keyboard.up("Control");

expect(await countStorageEntries(page))
.withContext(`In ${browserName}`)
.toEqual(3);

pastedContent = await page.$eval(`${editorPrefix}2`, el =>
el.innerText.trimEnd()
);
Expand Down Expand Up @@ -142,6 +161,10 @@ describe("Editor", () => {

expect(hasEditor).withContext(`In ${browserName}`).toEqual(false);
}

expect(await countStorageEntries(page))
.withContext(`In ${browserName}`)
.toEqual(0);
})
);
});
Expand Down

0 comments on commit 96c712f

Please sign in to comment.