Merge pull request #16652 from calixteman/rm_all_exceptions
[Editor] Avoid to throw when deleting some invisible editors
This commit is contained in:
commit
eb2527e9d7
@ -581,7 +581,11 @@ class AnnotationEditor {
|
|||||||
// undo/redo so we must commit it before.
|
// undo/redo so we must commit it before.
|
||||||
this.commit();
|
this.commit();
|
||||||
}
|
}
|
||||||
|
if (this.parent) {
|
||||||
this.parent.remove(this);
|
this.parent.remove(this);
|
||||||
|
} else {
|
||||||
|
this._uiManager.removeEditor(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -638,6 +642,9 @@ class AnnotationEditor {
|
|||||||
*/
|
*/
|
||||||
set isEditing(value) {
|
set isEditing(value) {
|
||||||
this.#isEditing = value;
|
this.#isEditing = value;
|
||||||
|
if (!this.parent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (value) {
|
if (value) {
|
||||||
this.parent.setSelected(this);
|
this.parent.setSelected(this);
|
||||||
this.parent.setActiveEditor(this);
|
this.parent.setActiveEditor(this);
|
||||||
|
@ -307,8 +307,10 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
remove() {
|
remove() {
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
|
if (this.parent) {
|
||||||
this.parent.setEditingState(true);
|
this.parent.setEditingState(true);
|
||||||
this.parent.div.classList.add("freeTextEditing");
|
this.parent.div.classList.add("freeTextEditing");
|
||||||
|
}
|
||||||
super.remove();
|
super.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +639,7 @@ describe("FreeText Editor", () => {
|
|||||||
await page.click("#editorFreeText");
|
await page.click("#editorFreeText");
|
||||||
let currentId = 0;
|
let currentId = 0;
|
||||||
const expected = [];
|
const expected = [];
|
||||||
const oneToFourteen = [...new Array(14).keys()].map(x => x + 1);
|
const oneToFourteen = Array.from(new Array(14).keys(), x => x + 1);
|
||||||
|
|
||||||
for (const pageNumber of oneToFourteen) {
|
for (const pageNumber of oneToFourteen) {
|
||||||
const pageSelector = `.page[data-page-number = "${pageNumber}"]`;
|
const pageSelector = `.page[data-page-number = "${pageNumber}"]`;
|
||||||
@ -1262,4 +1262,88 @@ describe("FreeText Editor", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("FreeText (remove)", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must delete invisible annotations", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
await page.click("#editorFreeText");
|
||||||
|
let currentId = 0;
|
||||||
|
const oneToFourteen = Array.from(new Array(14).keys(), x => x + 1);
|
||||||
|
|
||||||
|
for (const pageNumber of oneToFourteen) {
|
||||||
|
const pageSelector = `.page[data-page-number = "${pageNumber}"]`;
|
||||||
|
|
||||||
|
await page.evaluate(selector => {
|
||||||
|
const element = window.document.querySelector(selector);
|
||||||
|
element.scrollIntoView();
|
||||||
|
}, pageSelector);
|
||||||
|
|
||||||
|
const annotationLayerSelector = `${pageSelector} > .annotationEditorLayer`;
|
||||||
|
await page.waitForSelector(annotationLayerSelector, {
|
||||||
|
visible: true,
|
||||||
|
timeout: 0,
|
||||||
|
});
|
||||||
|
await page.waitForTimeout(50);
|
||||||
|
if (![1, 14].includes(pageNumber)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rect = await page.$eval(annotationLayerSelector, el => {
|
||||||
|
// With Chrome something is wrong when serializing a DomRect,
|
||||||
|
// hence we extract the values and just return them.
|
||||||
|
const { x, y } = el.getBoundingClientRect();
|
||||||
|
return { x, y };
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = `Hello PDF.js World !! on page ${pageNumber}`;
|
||||||
|
await page.mouse.click(rect.x + 100, rect.y + 100);
|
||||||
|
await page.type(`${getEditorSelector(currentId)} .internal`, data);
|
||||||
|
|
||||||
|
// Commit.
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
await page.waitForTimeout(10);
|
||||||
|
|
||||||
|
currentId += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select all.
|
||||||
|
await page.keyboard.down("Control");
|
||||||
|
await page.keyboard.press("a");
|
||||||
|
await page.keyboard.up("Control");
|
||||||
|
await page.waitForTimeout(10);
|
||||||
|
|
||||||
|
const serialize = () =>
|
||||||
|
page.evaluate(() => {
|
||||||
|
const { map } =
|
||||||
|
window.PDFViewerApplication.pdfDocument.annotationStorage
|
||||||
|
.serializable;
|
||||||
|
return map ? Array.from(map.values(), x => x.pageIndex) : [];
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await serialize())
|
||||||
|
.withContext(`In ${browserName}`)
|
||||||
|
.toEqual([0, 13]);
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
await page.keyboard.press("Backspace");
|
||||||
|
await page.waitForTimeout(10);
|
||||||
|
|
||||||
|
expect(await serialize())
|
||||||
|
.withContext(`In ${browserName}`)
|
||||||
|
.toEqual([]);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user