Merge pull request #20164 from calixteman/editor_hide_deleted_annotation
[Editor] Correctly hide deleted annotations
This commit is contained in:
commit
c6bd044438
@ -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);
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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),
|
||||
};
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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),
|
||||
};
|
||||
|
||||
@ -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
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -739,3 +739,4 @@
|
||||
!dates.pdf
|
||||
!dates_save.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