Merge pull request #16579 from calixteman/issue16577
[Editor] Don't make editable an empty freetext annotation
This commit is contained in:
commit
b8f5a14925
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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`
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user