From c4a832f4072516fe0be87a8e6c70e35ed88d0ba2 Mon Sep 17 00:00:00 2001 From: LoukasPap Date: Tue, 30 Jun 2026 19:24:39 +0300 Subject: [PATCH 1/2] Fix false enable of highlights when opening the editor menu --- src/display/editor/tools.js | 11 ++ test/integration/highlight_editor_spec.mjs | 150 +++++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 491b65a837ad3..93a5f900793c8 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -2162,6 +2162,13 @@ class AnnotationEditorUIManager { layer.updateMode(mode); } + const highlightShowAllState = this.#showAllStates?.get( + AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL + ); + if (highlightShowAllState !== undefined) { + this.showAllEditors("highlight", highlightShowAllState); + } + if (mode === AnnotationEditorType.POPUP) { this.#allEditableAnnotations ||= await this.#pdfDocument.getAnnotationsByType( @@ -2294,6 +2301,10 @@ class AnnotationEditorUIManager { this.#showAllStates?.get(AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL) ?? true; if (state !== visible) { + (this.#showAllStates ||= new Map()).set( + AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL, + visible + ); this.#dispatchUpdateUI([ [AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL, visible], ]); diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index d172b5ac52acd..94442dd434244 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -2848,4 +2848,154 @@ describe("Highlight Editor", () => { }); }); }); + + describe("Show all disabled status must be persistence", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer"); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must preserve the status when closing and opening any editor", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await switchToHighlight(page); + await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + + await highlightSpan(page, 1, "Abstract"); + const firstEditorSelector = getEditorSelector(0); + await page.waitForSelector(firstEditorSelector); + + const showAllButton = "#editorHighlightShowAll"; + await page.click(showAllButton); + await page.waitForSelector(`${firstEditorSelector}.hidden`); + + const modeChangedHandle1 = await waitForAnnotationModeChanged(page); + await page.click("#editorHighlightButton"); + await awaitPromise(modeChangedHandle1); + + const modeChangedHandle2 = await waitForAnnotationModeChanged(page); + await page.click("#editorInkButton"); + await awaitPromise(modeChangedHandle2); + await page.waitForSelector(".annotationEditorLayer.inkEditing"); + + const modeChangedHandle3 = await waitForAnnotationModeChanged(page); + await page.click("#editorHighlightButton"); + await awaitPromise(modeChangedHandle3); + await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + + const isShowAllDisabled = await page.evaluate(() => { + const btn = document.querySelector("#editorHighlightShowAll"); + return btn.getAttribute("aria-pressed") === "false"; + }); + + expect(isShowAllDisabled) + .withContext( + `In ${browserName}: Show all button should still be disabled` + ) + .toBe(true); + + const visibilityState = await page.evaluate(selector => { + const highlight = document.querySelector(selector); + return { + hasHiddenClass: highlight + ? highlight.classList.contains("hidden") + : false, + }; + }, firstEditorSelector); + + expect(visibilityState.hasHiddenClass) + .withContext( + `In ${browserName}: Highlight should have hidden CSS class` + ) + .toBe(true); + }) + ); + }); + + it("must preserve the status when highlighting from edit toolbar and re-opening the editor", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await switchToHighlight(page); + await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + + await highlightSpan(page, 1, "Abstract"); + const firstEditorSelector = getEditorSelector(0); + await page.waitForSelector(firstEditorSelector); + + const showAllButton = "#editorHighlightShowAll"; + await page.click(showAllButton); + await page.waitForSelector(`${firstEditorSelector}.hidden`); + + const modeChangedHandle = await waitForAnnotationModeChanged(page); + await page.click("#editorHighlightButton"); + await awaitPromise(modeChangedHandle); + + const textSpan = await page.$( + `.page[data-page-number = "1"] .textLayer span` + ); + const spanRect = await page.evaluate(el => { + const rect = el.getBoundingClientRect(); + return { + x: rect.x + rect.width / 2, + y: rect.y + rect.height / 2, + }; + }, textSpan); + + await page.mouse.click(spanRect.x, spanRect.y); + await page.mouse.click(spanRect.x, spanRect.y); + + await page.waitForSelector(".editToolbar", { timeout: 5000 }); + const highlightFromToolbar = await page.$( + ".floatingToolbar button[data-action='highlight']" + ); + if (highlightFromToolbar) { + await highlightFromToolbar.click(); + const secondEditorSelector = getEditorSelector(1); + await page.waitForSelector(secondEditorSelector); + } + + const modeChangedHandle2 = await waitForAnnotationModeChanged(page); + await page.click("#editorHighlightButton"); + await awaitPromise(modeChangedHandle2); + + const modeChangedHandle3 = await waitForAnnotationModeChanged(page); + await page.click("#editorHighlightButton"); + await awaitPromise(modeChangedHandle3); + + const isShowAllDisabled = await page.evaluate(() => { + const btn = document.querySelector("#editorHighlightShowAll"); + return btn.getAttribute("aria-pressed") === "false"; + }); + + expect(isShowAllDisabled) + .withContext( + `In ${browserName}: Show all button should still be disabled` + ) + .toBe(true); + + await page.waitForSelector(`${firstEditorSelector}.hidden`); + + const visibilityState = await page.evaluate(selector => { + const highlight = document.querySelector(selector); + return { + hasHiddenClass: highlight + ? highlight.classList.contains("hidden") + : false, + }; + }, firstEditorSelector); + + expect(visibilityState.hasHiddenClass) + .withContext( + `In ${browserName}: Highlight should have hidden CSS class after floating toolbar usage` + ) + .toBe(true); + }) + ); + }); + }); }); From b441120503ebe2e7a8ee522425f24d3265cbc100 Mon Sep 17 00:00:00 2001 From: Loukas Papadopoulos Date: Sat, 4 Jul 2026 15:16:07 +0300 Subject: [PATCH 2/2] Remove timeout --- test/integration/highlight_editor_spec.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 94442dd434244..2bd02a7b3c6a2 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -2949,7 +2949,7 @@ describe("Highlight Editor", () => { await page.mouse.click(spanRect.x, spanRect.y); await page.mouse.click(spanRect.x, spanRect.y); - await page.waitForSelector(".editToolbar", { timeout: 5000 }); + await page.waitForSelector(".editToolbar"); const highlightFromToolbar = await page.$( ".floatingToolbar button[data-action='highlight']" );