Skip to content

Commit a7645cc

Browse files
committed
Fix false enable of highlights when opening the editor menu
1 parent 8bc2fe6 commit a7645cc

2 files changed

Lines changed: 153 additions & 0 deletions

File tree

src/display/editor/tools.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,13 @@ class AnnotationEditorUIManager {
21622162
layer.updateMode(mode);
21632163
}
21642164

2165+
const highlightShowAllState = this.#showAllStates?.get(
2166+
AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL
2167+
);
2168+
if (highlightShowAllState !== undefined) {
2169+
this.showAllEditors("highlight", highlightShowAllState);
2170+
}
2171+
21652172
if (mode === AnnotationEditorType.POPUP) {
21662173
this.#allEditableAnnotations ||=
21672174
await this.#pdfDocument.getAnnotationsByType(
@@ -2294,6 +2301,10 @@ class AnnotationEditorUIManager {
22942301
this.#showAllStates?.get(AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL) ??
22952302
true;
22962303
if (state !== visible) {
2304+
(this.#showAllStates ||= new Map()).set(
2305+
AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL,
2306+
visible
2307+
);
22972308
this.#dispatchUpdateUI([
22982309
[AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL, visible],
22992310
]);

test/integration/highlight_editor_spec.mjs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,4 +2848,146 @@ describe("Highlight Editor", () => {
28482848
});
28492849
});
28502850
});
2851+
2852+
describe("Show all disabled status must be persistent", () => {
2853+
let pages;
2854+
2855+
beforeEach(async () => {
2856+
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
2857+
});
2858+
2859+
afterEach(async () => {
2860+
await closePages(pages);
2861+
});
2862+
2863+
it("must preserve the status when closing and opening any editor", async () => {
2864+
await Promise.all(
2865+
pages.map(async ([browserName, page]) => {
2866+
await switchToHighlight(page);
2867+
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
2868+
2869+
await highlightSpan(page, 1, "Abstract");
2870+
const firstEditorSelector = getEditorSelector(0);
2871+
await page.waitForSelector(firstEditorSelector);
2872+
2873+
const showAllButton = "#editorHighlightShowAll";
2874+
await page.click(showAllButton);
2875+
await page.waitForSelector(`${firstEditorSelector}.hidden`);
2876+
2877+
const modeChangedHandle1 = await waitForAnnotationModeChanged(page);
2878+
await page.click("#editorHighlightButton");
2879+
await awaitPromise(modeChangedHandle1);
2880+
2881+
const modeChangedHandle2 = await waitForAnnotationModeChanged(page);
2882+
await page.click("#editorInkButton");
2883+
await awaitPromise(modeChangedHandle2);
2884+
await page.waitForSelector(".annotationEditorLayer.inkEditing");
2885+
2886+
const modeChangedHandle3 = await waitForAnnotationModeChanged(page);
2887+
await page.click("#editorHighlightButton");
2888+
await awaitPromise(modeChangedHandle3);
2889+
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
2890+
2891+
const isShowAllDisabled = await page.evaluate(() => {
2892+
const btn = document.querySelector("#editorHighlightShowAll");
2893+
return btn.getAttribute("aria-pressed") === "false";
2894+
});
2895+
2896+
expect(isShowAllDisabled)
2897+
.withContext(
2898+
`In ${browserName}: Show all button should still be disabled`
2899+
)
2900+
.toBe(true);
2901+
2902+
const hasHiddenClass = await page.evaluate(selector => {
2903+
const highlight = document.querySelector(selector);
2904+
return highlight ? highlight.classList.contains("hidden") : false;
2905+
}, firstEditorSelector);
2906+
2907+
expect(hasHiddenClass)
2908+
.withContext(
2909+
`In ${browserName}: Highlight should have hidden CSS class`
2910+
)
2911+
.toBe(true);
2912+
})
2913+
);
2914+
});
2915+
2916+
it("must preserve the status when highlighting from edit toolbar and re-opening the editor", async () => {
2917+
await Promise.all(
2918+
pages.map(async ([browserName, page]) => {
2919+
await switchToHighlight(page);
2920+
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
2921+
2922+
await highlightSpan(page, 1, "Abstract");
2923+
const firstEditorSelector = getEditorSelector(0);
2924+
await page.waitForSelector(firstEditorSelector);
2925+
2926+
const showAllButton = "#editorHighlightShowAll";
2927+
await page.click(showAllButton);
2928+
await page.waitForSelector(`${firstEditorSelector}.hidden`);
2929+
2930+
const modeChangedHandle = await waitForAnnotationModeChanged(page);
2931+
await page.click("#editorHighlightButton");
2932+
await awaitPromise(modeChangedHandle);
2933+
2934+
const textSpan = await page.$(
2935+
`.page[data-page-number = "1"] .textLayer span`
2936+
);
2937+
const spanRect = await page.evaluate(el => {
2938+
const rect = el.getBoundingClientRect();
2939+
return {
2940+
x: rect.x + rect.width / 2,
2941+
y: rect.y + rect.height / 2,
2942+
};
2943+
}, textSpan);
2944+
2945+
await page.mouse.click(spanRect.x, spanRect.y);
2946+
await page.mouse.click(spanRect.x, spanRect.y);
2947+
2948+
await page.waitForSelector(".editToolbar");
2949+
const highlightFromToolbar = await page.$(
2950+
".editToolbar .highlightButton"
2951+
);
2952+
if (highlightFromToolbar) {
2953+
await highlightFromToolbar.click();
2954+
const secondEditorSelector = getEditorSelector(1);
2955+
await page.waitForSelector(secondEditorSelector);
2956+
}
2957+
2958+
const modeChangedHandle2 = await waitForAnnotationModeChanged(page);
2959+
await page.click("#editorHighlightButton");
2960+
await awaitPromise(modeChangedHandle2);
2961+
2962+
const modeChangedHandle3 = await waitForAnnotationModeChanged(page);
2963+
await page.click("#editorHighlightButton");
2964+
await awaitPromise(modeChangedHandle3);
2965+
2966+
const isShowAllDisabled = await page.evaluate(() => {
2967+
const btn = document.querySelector("#editorHighlightShowAll");
2968+
return btn.getAttribute("aria-pressed") === "false";
2969+
});
2970+
2971+
expect(isShowAllDisabled)
2972+
.withContext(
2973+
`In ${browserName}: Show all button should still be disabled`
2974+
)
2975+
.toBe(true);
2976+
2977+
await page.waitForSelector(`${firstEditorSelector}.hidden`);
2978+
2979+
const hasHiddenClass = await page.evaluate(selector => {
2980+
const highlight = document.querySelector(selector);
2981+
return highlight ? highlight.classList.contains("hidden") : false;
2982+
}, firstEditorSelector);
2983+
2984+
expect(hasHiddenClass)
2985+
.withContext(
2986+
`In ${browserName}: Highlight should have hidden CSS class`
2987+
)
2988+
.toBe(true);
2989+
})
2990+
);
2991+
});
2992+
});
28512993
});

0 commit comments

Comments
 (0)