mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[Editor] Don't steal the keyboard events when editing mode is enabled
This commit is contained in:
parent
1ab0f8a0ec
commit
77475ac610
2 changed files with 90 additions and 6 deletions
|
@ -2981,4 +2981,76 @@ describe("FreeText Editor", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Avoid to steal keyboard events", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check the keyboard event is limited to the input", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await switchToFreeText(page);
|
||||
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
// With Chrome something is wrong when serializing a DomRect,
|
||||
// hence we extract the values and just return them.
|
||||
const { x, y } = el.getBoundingClientRect();
|
||||
return { x, y };
|
||||
});
|
||||
|
||||
const data = "Hello PDF.js World !!";
|
||||
await page.mouse.click(rect.x + 100, rect.y + 100);
|
||||
await page.waitForSelector(getEditorSelector(0), {
|
||||
visible: true,
|
||||
});
|
||||
await page.type(`${getEditorSelector(0)} .internal`, data);
|
||||
|
||||
// Commit.
|
||||
await page.keyboard.press("Escape");
|
||||
await page.waitForSelector(
|
||||
`${getEditorSelector(0)} .overlay.enabled`
|
||||
);
|
||||
|
||||
let promise = page.evaluate(
|
||||
() =>
|
||||
new Promise(resolve => {
|
||||
document.addEventListener("selectionchange", resolve, {
|
||||
once: true,
|
||||
});
|
||||
})
|
||||
);
|
||||
await page.click("#pageNumber");
|
||||
await promise;
|
||||
|
||||
promise = page.evaluate(
|
||||
() =>
|
||||
new Promise(resolve => {
|
||||
document
|
||||
.getElementById("pageNumber")
|
||||
.addEventListener("keyup", resolve, { once: true });
|
||||
})
|
||||
);
|
||||
await page.keyboard.press("Backspace");
|
||||
await promise;
|
||||
|
||||
let content = await page.$eval("#pageNumber", el =>
|
||||
el.innerText.trimEnd()
|
||||
);
|
||||
expect(content).withContext(`In ${browserName}`).toEqual("");
|
||||
|
||||
content = await page.$eval(getEditorSelector(0), el =>
|
||||
el.innerText.trimEnd()
|
||||
);
|
||||
expect(content).withContext(`In ${browserName}`).toEqual(data);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue