Fix free highlight on pages without images (bug 2035530)

This commit is contained in:
Calixte Denizet 2026-04-29 19:24:35 +02:00
parent 34c3ee16f8
commit e7ec356be0
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
3 changed files with 51 additions and 1 deletions

View File

@ -466,6 +466,7 @@ class AnnotationEditorLayer {
target === this.#textLayer.div ||
((target.getAttribute("role") === "img" ||
target.classList.contains("endOfContent") ||
target.classList.contains("textLayerImages") ||
target.classList.contains("textLayerImagePlaceholder")) &&
this.#textLayer.div.contains(target))
) {

View File

@ -347,4 +347,53 @@ describe("Text layer images", () => {
);
});
});
describe("free-highlighting on a page with no images", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait(
"empty.pdf",
`.page[data-page-number = "1"] .textLayerImages`,
undefined,
undefined,
{
imagesRightClickMinSize: 16,
highlightEditorColors: "yellow=#FFFF00",
},
{ width: 800, height: 600, devicePixelRatio: 1 }
);
});
afterEach(async () => {
await closePages(pages);
});
it("must create a free highlight when dragging on the empty image container", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);
const rect = await getRect(
page,
`.page[data-page-number="1"] > .textLayer > .textLayerImages`
);
const x1 = rect.x + rect.width / 4;
const y1 = rect.y + rect.height / 4;
const x2 = rect.x + (3 * rect.width) / 4;
const y2 = rect.y + (3 * rect.height) / 4;
const clickHandle = await waitForPointerUp(page);
await page.mouse.move(x1, y1);
await page.mouse.down();
await page.mouse.move(x2, y2);
await page.mouse.up();
await awaitPromise(clickHandle);
await page.waitForSelector(getEditorSelector(0));
})
);
});
});
});

View File

@ -323,7 +323,7 @@ const defaultOptions = {
imagesRightClickMinSize: {
/** @type {number} */
value:
typeof PDFJSDev !== "undefined" &&
typeof PDFJSDev === "undefined" ||
// Firefox mobile does not support right-clicking on images,
// see https://bugzilla.mozilla.org/show_bug.cgi?id=2014081.
// This option is disabled by default outside of MOZCENTRAL