1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

Merge pull request #17650 from calixteman/editor_highlight_keyboard

[Editor] Add a way to highlight text in using the keyboard (bug 1877426)
This commit is contained in:
calixteman 2024-02-11 18:52:37 +01:00 committed by GitHub
commit f15b4b34fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 107 additions and 7 deletions

View file

@ -681,4 +681,64 @@ describe("Highlight Editor", () => {
);
});
});
describe("Highlight with the keyboard", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that some text has been highlighted", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.click("#editorHighlight");
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
const sel = getEditorSelector(0);
const spanRect = await page.evaluate(() => {
const span = document.querySelector(
`.page[data-page-number="1"] > .textLayer > span`
);
const { x, y, width, height } = span.getBoundingClientRect();
return { x, y, width, height };
});
await page.keyboard.down("Shift");
await page.mouse.click(
spanRect.x + 1,
spanRect.y + spanRect.height / 2,
{ count: 2 }
);
for (let i = 0; i < 6; i++) {
await page.keyboard.press("ArrowRight");
}
await page.keyboard.press("ArrowDown");
await page.keyboard.press("ArrowDown");
await page.keyboard.up("Shift");
const [w, h] = await page.evaluate(s => {
const {
style: { width, height },
} = document.querySelector(s);
return [parseFloat(width), parseFloat(height)];
}, sel);
// w & h are the width and height of the highlight in percent.
// We expect the highlight to be around 73% wide and 9% high.
// We allow a 2% margin of error because of the font used in the text
// layer we can't be sure of the dimensions.
expect(Math.abs(w - 73) <= 2)
.withContext(`In ${browserName}`)
.toBe(true);
expect(Math.abs(h - 9) <= 2)
.withContext(`In ${browserName}`)
.toBe(true);
})
);
});
});
});