mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[Editor] Move an the editor div in the DOM once a translation with the keyboard is done
When moving an element in the DOM, the focus is potentially lost, so we need to make sure that the focused element before the translation will get back its focus after it. But we must take care to not execute any focus/blur callbacks because the user didn't do anything which should trigger such events: it's a detail of implementation. For example, when several editors are selected and moved, then at the end the same must be selected, so no element receive a focus event which will set it as selected.
This commit is contained in:
parent
ec2b717705
commit
7d8b53bf7a
6 changed files with 134 additions and 13 deletions
|
@ -390,6 +390,7 @@ describe("FreeText Editor", () => {
|
|||
await clearAll(page);
|
||||
|
||||
await page.mouse.click(rect.x + 200, rect.y + 100);
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await page.type(`${getEditorSelector(9)} .internal`, "A");
|
||||
|
@ -2111,4 +2112,85 @@ describe("FreeText Editor", () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Freetext must stay focused after having been moved", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must keep the focus", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await page.click("#editorFreeText");
|
||||
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
const { x, y } = el.getBoundingClientRect();
|
||||
return { x, y };
|
||||
});
|
||||
|
||||
await page.mouse.click(rect.x + 100, rect.y + 100);
|
||||
await page.waitForTimeout(10);
|
||||
await page.type(`${getEditorSelector(0)} .internal`, "A");
|
||||
|
||||
// Commit.
|
||||
await page.keyboard.press("Escape");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
await page.mouse.click(rect.x + 110, rect.y + 150);
|
||||
await page.waitForTimeout(10);
|
||||
await page.type(`${getEditorSelector(0)} .internal`, "B");
|
||||
|
||||
// Commit.
|
||||
await page.keyboard.press("Escape");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
await page.mouse.click(rect.x + 115, rect.y + 155);
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
const pos = n =>
|
||||
page.evaluate(sel => {
|
||||
const editor = document.querySelector(sel);
|
||||
return Array.prototype.indexOf.call(
|
||||
editor.parentNode.childNodes,
|
||||
editor
|
||||
);
|
||||
}, getEditorSelector(n));
|
||||
|
||||
expect(await pos(0))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(0);
|
||||
expect(await pos(1))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(1);
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.keyboard.up("Control");
|
||||
await page.waitForTimeout(1);
|
||||
}
|
||||
|
||||
await page.waitForTimeout(100);
|
||||
const focused = await page.evaluate(sel => {
|
||||
const editor = document.querySelector(sel);
|
||||
return editor === document.activeElement;
|
||||
}, getEditorSelector(1));
|
||||
expect(focused).withContext(`In ${browserName}`).toEqual(true);
|
||||
|
||||
expect(await pos(0))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(1);
|
||||
expect(await pos(1))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(0);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -50,23 +50,28 @@ describe("Ink Editor", () => {
|
|||
await page.mouse.down();
|
||||
await page.mouse.move(x + 50, y + 50);
|
||||
await page.mouse.up();
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await page.waitForTimeout(10);
|
||||
}
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual([0, 1, 2]);
|
||||
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("z");
|
||||
await page.keyboard.up("Control");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
expect(await getSelectedEditors(page))
|
||||
.withContext(`In ${browserName}`)
|
||||
|
@ -81,8 +86,10 @@ describe("Ink Editor", () => {
|
|||
await page.keyboard.down("Control");
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.up("Control");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||
// With Chrome something is wrong when serializing a DomRect,
|
||||
|
@ -97,8 +104,10 @@ describe("Ink Editor", () => {
|
|||
await page.mouse.down();
|
||||
await page.mouse.move(xStart + 50, yStart + 50);
|
||||
await page.mouse.up();
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await page.waitForTimeout(10);
|
||||
|
||||
const rectBefore = await page.$eval(".inkEditor canvas", el => {
|
||||
const { x, y } = el.getBoundingClientRect();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue