[Editor] Correctly hide deleted annotations

This commit is contained in:
Calixte Denizet 2025-08-13 22:40:53 +02:00
parent 7ea7a94ed5
commit 6a00174688
9 changed files with 80 additions and 3 deletions

View File

@ -359,9 +359,7 @@ class AnnotationEditorLayer {
for (const editable of editables) {
const { id } = editable.data;
if (this.#uiManager.isDeletedAnnotationElement(id)) {
editable.updateEdited({
deleted: true,
});
editable.updateEdited({ deleted: true });
continue;
}
let editor = resetAnnotations.get(id);

View File

@ -2155,6 +2155,10 @@ class AnnotationEditor {
* @returns {HTMLElement|null}
*/
renderAnnotationElement(annotation) {
if (this.deleted) {
annotation.hide();
return null;
}
let content = annotation.container.querySelector(".annotationContent");
if (!content) {
content = document.createElement("div");

View File

@ -885,6 +885,9 @@ class FreeTextEditor extends AnnotationEditor {
/** @inheritdoc */
renderAnnotationElement(annotation) {
const content = super.renderAnnotationElement(annotation);
if (!content) {
return null;
}
const { style } = content;
style.fontSize = `calc(${this.#fontSize}px * var(--total-scale-factor))`;
style.color = this.#color;

View File

@ -1059,6 +1059,10 @@ class HighlightEditor extends AnnotationEditor {
/** @inheritdoc */
renderAnnotationElement(annotation) {
if (this.deleted) {
annotation.hide();
return null;
}
const params = {
rect: this.getRect(0, 0),
};

View File

@ -295,6 +295,10 @@ class InkEditor extends DrawingEditor {
/** @inheritdoc */
renderAnnotationElement(annotation) {
if (this.deleted) {
annotation.hide();
return null;
}
const { points, rect } = this.serializeDraw(/* isForCopying = */ false);
const params = {
rect,

View File

@ -930,6 +930,10 @@ class StampEditor extends AnnotationEditor {
/** @inheritdoc */
renderAnnotationElement(annotation) {
if (this.deleted) {
annotation.hide();
return null;
}
const params = {
rect: this.getRect(0, 0),
};

View File

@ -37,6 +37,7 @@ import {
kbModifierDown,
kbModifierUp,
kbRedo,
kbSelectAll,
kbUndo,
loadAndWait,
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
);
})
);
});
});
});

View File

@ -739,3 +739,4 @@
!dates.pdf
!dates_save.pdf
!print_protection.pdf
!tracemonkey_with_annotations.pdf

Binary file not shown.