[Editor] Correctly hide deleted annotations
This commit is contained in:
parent
7ea7a94ed5
commit
6a00174688
@ -359,9 +359,7 @@ class AnnotationEditorLayer {
|
|||||||
for (const editable of editables) {
|
for (const editable of editables) {
|
||||||
const { id } = editable.data;
|
const { id } = editable.data;
|
||||||
if (this.#uiManager.isDeletedAnnotationElement(id)) {
|
if (this.#uiManager.isDeletedAnnotationElement(id)) {
|
||||||
editable.updateEdited({
|
editable.updateEdited({ deleted: true });
|
||||||
deleted: true,
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let editor = resetAnnotations.get(id);
|
let editor = resetAnnotations.get(id);
|
||||||
|
|||||||
@ -2155,6 +2155,10 @@ class AnnotationEditor {
|
|||||||
* @returns {HTMLElement|null}
|
* @returns {HTMLElement|null}
|
||||||
*/
|
*/
|
||||||
renderAnnotationElement(annotation) {
|
renderAnnotationElement(annotation) {
|
||||||
|
if (this.deleted) {
|
||||||
|
annotation.hide();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let content = annotation.container.querySelector(".annotationContent");
|
let content = annotation.container.querySelector(".annotationContent");
|
||||||
if (!content) {
|
if (!content) {
|
||||||
content = document.createElement("div");
|
content = document.createElement("div");
|
||||||
|
|||||||
@ -885,6 +885,9 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
renderAnnotationElement(annotation) {
|
renderAnnotationElement(annotation) {
|
||||||
const content = super.renderAnnotationElement(annotation);
|
const content = super.renderAnnotationElement(annotation);
|
||||||
|
if (!content) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const { style } = content;
|
const { style } = content;
|
||||||
style.fontSize = `calc(${this.#fontSize}px * var(--total-scale-factor))`;
|
style.fontSize = `calc(${this.#fontSize}px * var(--total-scale-factor))`;
|
||||||
style.color = this.#color;
|
style.color = this.#color;
|
||||||
|
|||||||
@ -1059,6 +1059,10 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
renderAnnotationElement(annotation) {
|
renderAnnotationElement(annotation) {
|
||||||
|
if (this.deleted) {
|
||||||
|
annotation.hide();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const params = {
|
const params = {
|
||||||
rect: this.getRect(0, 0),
|
rect: this.getRect(0, 0),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -295,6 +295,10 @@ class InkEditor extends DrawingEditor {
|
|||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
renderAnnotationElement(annotation) {
|
renderAnnotationElement(annotation) {
|
||||||
|
if (this.deleted) {
|
||||||
|
annotation.hide();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const { points, rect } = this.serializeDraw(/* isForCopying = */ false);
|
const { points, rect } = this.serializeDraw(/* isForCopying = */ false);
|
||||||
const params = {
|
const params = {
|
||||||
rect,
|
rect,
|
||||||
|
|||||||
@ -930,6 +930,10 @@ class StampEditor extends AnnotationEditor {
|
|||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
renderAnnotationElement(annotation) {
|
renderAnnotationElement(annotation) {
|
||||||
|
if (this.deleted) {
|
||||||
|
annotation.hide();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const params = {
|
const params = {
|
||||||
rect: this.getRect(0, 0),
|
rect: this.getRect(0, 0),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import {
|
|||||||
kbModifierDown,
|
kbModifierDown,
|
||||||
kbModifierUp,
|
kbModifierUp,
|
||||||
kbRedo,
|
kbRedo,
|
||||||
|
kbSelectAll,
|
||||||
kbUndo,
|
kbUndo,
|
||||||
loadAndWait,
|
loadAndWait,
|
||||||
moveEditor,
|
moveEditor,
|
||||||
@ -3547,4 +3548,62 @@ describe("FreeText Editor", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Delete some annotations, scroll to the end and then scroll to the beginning", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
pages = await loadAndWait(
|
||||||
|
"tracemonkey_with_annotations.pdf",
|
||||||
|
".annotationEditorLayer"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must check that the annotations aren't displayed after scrolling", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
await switchToFreeText(page);
|
||||||
|
|
||||||
|
await kbSelectAll(page);
|
||||||
|
await page.waitForFunction(
|
||||||
|
() => document.querySelectorAll(".selectedEditor").length === 4
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.keyboard.press("Backspace");
|
||||||
|
await page.waitForFunction(() => {
|
||||||
|
const { map } =
|
||||||
|
window.PDFViewerApplication.pdfDocument.annotationStorage
|
||||||
|
.serializable;
|
||||||
|
return (
|
||||||
|
map.size === 4 && [...map.values()].every(entry => entry.deleted)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disable editing mode.
|
||||||
|
await switchToFreeText(page, /* disable = */ true);
|
||||||
|
|
||||||
|
const oneToOne = Array.from(new Array(13).keys(), n => n + 2).concat(
|
||||||
|
Array.from(new Array(13).keys(), n => 13 - n)
|
||||||
|
);
|
||||||
|
for (const pageNumber of oneToOne) {
|
||||||
|
await scrollIntoView(
|
||||||
|
page,
|
||||||
|
`.page[data-page-number = "${pageNumber}"]`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await page.waitForFunction(
|
||||||
|
() =>
|
||||||
|
document.querySelectorAll(
|
||||||
|
`.annotationLayer > section:is(.stampAnnotation, .inkAnnotation, .highlightAnnotation, .freeTextAnnotation)[hidden = ""]`
|
||||||
|
).length === 4
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -739,3 +739,4 @@
|
|||||||
!dates.pdf
|
!dates.pdf
|
||||||
!dates_save.pdf
|
!dates_save.pdf
|
||||||
!print_protection.pdf
|
!print_protection.pdf
|
||||||
|
!tracemonkey_with_annotations.pdf
|
||||||
|
|||||||
BIN
test/pdfs/tracemonkey_with_annotations.pdf
Executable file
BIN
test/pdfs/tracemonkey_with_annotations.pdf
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user