Skip to content

Commit 33e638c

Browse files
Merge pull request #20282 from calixteman/fix_showing_invisible_editor
[Editor] Make sure to not add extra editors when showing again a destroyed page
2 parents 20f31d7 + cbc5241 commit 33e638c

3 files changed

Lines changed: 103 additions & 7 deletions

File tree

src/display/editor/annotation_editor_layer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ class AnnotationEditorLayer {
238238
this.#annotationLayer?.div.classList.toggle("disabled", !enabled);
239239
}
240240

241+
get #allEditorsIterator() {
242+
return this.#editors.size !== 0
243+
? this.#editors.values()
244+
: this.#uiManager.getEditors(this.pageIndex);
245+
}
246+
241247
/**
242248
* Enable pointer events on the main div in order to enable
243249
* editor creation.
@@ -249,7 +255,7 @@ class AnnotationEditorLayer {
249255
this.#textLayerDblClickAC?.abort();
250256
this.#textLayerDblClickAC = null;
251257
const annotationElementIds = new Set();
252-
for (const editor of this.#editors.values()) {
258+
for (const editor of this.#allEditorsIterator) {
253259
editor.enableEditing();
254260
editor.show(true);
255261
if (editor.annotationElementId) {
@@ -342,7 +348,7 @@ class AnnotationEditorLayer {
342348
}
343349
const changedAnnotations = new Map();
344350
const resetAnnotations = new Map();
345-
for (const editor of this.#editors.values()) {
351+
for (const editor of this.#allEditorsIterator) {
346352
editor.disableEditing();
347353
if (!editor.annotationElementId) {
348354
continue;

src/display/editor/tools.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,16 +2087,14 @@ class AnnotationEditorUIManager {
20872087
/**
20882088
* Get all the editors belonging to a given page.
20892089
* @param {number} pageIndex
2090-
* @returns {Array<AnnotationEditor>}
2090+
* @yields {AnnotationEditor}
20912091
*/
2092-
getEditors(pageIndex) {
2093-
const editors = [];
2092+
*getEditors(pageIndex) {
20942093
for (const editor of this.#allEditors.values()) {
20952094
if (editor.pageIndex === pageIndex) {
2096-
editors.push(editor);
2095+
yield editor;
20972096
}
20982097
}
2099-
return editors;
21002098
}
21012099

21022100
/**

test/integration/highlight_editor_spec.mjs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,4 +2861,96 @@ describe("Highlight Editor", () => {
28612861
);
28622862
});
28632863
});
2864+
2865+
describe("Highlight (edit existing and scroll)", () => {
2866+
let pages;
2867+
2868+
beforeEach(async () => {
2869+
pages = await loadAndWait(
2870+
"highlights.pdf",
2871+
".annotationEditorLayer",
2872+
null,
2873+
null,
2874+
{
2875+
highlightEditorColors:
2876+
"yellow=#FFFF00,green=#00FF00,blue=#0000FF,pink=#FF00FF,red=#FF0102",
2877+
}
2878+
);
2879+
});
2880+
2881+
afterEach(async () => {
2882+
await closePages(pages);
2883+
});
2884+
2885+
it("must check that no extra annotations are added while in editing mode", async () => {
2886+
await Promise.all(
2887+
pages.map(async ([browserName, page]) => {
2888+
await switchToHighlight(page);
2889+
2890+
const editorSelector = getEditorSelector(7);
2891+
await page.waitForSelector(editorSelector);
2892+
2893+
const oneToOne = Array.from(new Array(13).keys(), n => n + 2).concat(
2894+
Array.from(new Array(13).keys(), n => 13 - n)
2895+
);
2896+
for (const pageNumber of oneToOne) {
2897+
await scrollIntoView(
2898+
page,
2899+
`.page[data-page-number = "${pageNumber}"]`
2900+
);
2901+
}
2902+
2903+
await page.waitForSelector(editorSelector);
2904+
2905+
const count = await page.evaluate(
2906+
() =>
2907+
document.querySelectorAll(
2908+
`.page[data-page-number = "1"] .annotationEditorLayer .highlightEditor`
2909+
).length
2910+
);
2911+
expect(count).withContext(`In ${browserName}`).toEqual(8);
2912+
})
2913+
);
2914+
});
2915+
2916+
it("must check that no extra annotations are added while in reading mode", async () => {
2917+
await Promise.all(
2918+
pages.map(async ([browserName, page]) => {
2919+
await switchToHighlight(page);
2920+
2921+
const editorSelector = getEditorSelector(7);
2922+
await page.waitForSelector(editorSelector);
2923+
2924+
const oneToThirteen = Array.from(new Array(13).keys(), n => n + 2);
2925+
const thirteenToOne = Array.from(new Array(13).keys(), n => 13 - n);
2926+
for (const pageNumber of oneToThirteen) {
2927+
await scrollIntoView(
2928+
page,
2929+
`.page[data-page-number = "${pageNumber}"]`
2930+
);
2931+
}
2932+
2933+
await switchToHighlight(page, /* disable */ true);
2934+
2935+
for (const pageNumber of thirteenToOne) {
2936+
await scrollIntoView(
2937+
page,
2938+
`.page[data-page-number = "${pageNumber}"]`
2939+
);
2940+
}
2941+
2942+
await page.waitForSelector(
2943+
`.page[data-page-number = "1"] .annotationEditorLayer.disabled`
2944+
);
2945+
2946+
await page.waitForFunction(
2947+
() =>
2948+
document.querySelectorAll(
2949+
`.page[data-page-number = "1"] .annotationEditorLayer .highlightEditor`
2950+
).length === 0
2951+
);
2952+
})
2953+
);
2954+
});
2955+
});
28642956
});

0 commit comments

Comments
 (0)