Merge pull request #16579 from calixteman/issue16577

[Editor] Don't make editable an empty freetext annotation
This commit is contained in:
calixteman 2023-06-21 12:26:02 +02:00 committed by GitHub
commit b8f5a14925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 1 deletions

View File

@ -999,6 +999,9 @@ class Annotation {
enqueue(chunk, size) {
for (const item of chunk.items) {
if (item.str === undefined) {
continue;
}
buffer.push(item.str);
if (item.hasEOL) {
text.push(buffer.join(""));
@ -1022,7 +1025,7 @@ class Annotation {
text.push(buffer.join(""));
}
if (text.length > 0) {
if (text.length > 1 || text[0]) {
this.data.textContent = text;
}
}

View File

@ -541,6 +541,8 @@ class FreeTextEditor extends AnnotationEditor {
page: { pageNumber },
},
} = data;
// textContent is supposed to be an array of strings containing each line
// of text. However, it can be null or empty.
if (!textContent || textContent.length === 0) {
// Empty annotation.
return null;

View File

@ -1116,4 +1116,42 @@ describe("FreeText Editor", () => {
}
});
});
describe("FreeText with popup", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait(
"annotation-freetext.pdf",
".annotationEditorLayer"
);
});
afterAll(async () => {
await closePages(pages);
});
it("must not remove an empty annotation", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.hover("[data-annotation-id='23R']");
// Wait for the popup to be displayed.
await page.waitForFunction(
`document.querySelector("[data-annotation-id='popup_23R']").hidden === false`
);
// Enter in editing mode.
await page.click("#editorFreeText");
await page.waitForTimeout(10);
await page.click("#editorFreeText");
await page.hover("[data-annotation-id='23R']");
// Wait for the popup to be displayed.
await page.waitForFunction(
`document.querySelector("[data-annotation-id='popup_23R']").hidden === false`
);
})
);
});
});
});