1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[Editor] Add the possibility to move all the selected editors with the mouse (bug 1847894)

This commit is contained in:
Calixte Denizet 2023-08-09 11:23:26 +02:00
parent d4ba312f00
commit 402e3fed95
9 changed files with 292 additions and 85 deletions

View file

@ -921,6 +921,9 @@ describe("FreeText Editor", () => {
return { x, y, width, height };
});
// Select the annotation we want to move.
await page.mouse.click(editorRect.x + 2, editorRect.y + 2);
await dragAndDropAnnotation(
page,
editorRect.x + editorRect.width / 2,
@ -2193,4 +2196,73 @@ describe("FreeText Editor", () => {
);
});
});
describe("Move several FreeTexts", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
});
afterAll(async () => {
await closePages(pages);
});
it("must move several annotations", 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 };
});
const allPositions = [];
for (let i = 0; i < 10; i++) {
await page.mouse.click(rect.x + 10 + 30 * i, rect.y + 100 + 5 * i);
await page.waitForTimeout(10);
await page.type(
`${getEditorSelector(i)} .internal`,
String.fromCharCode(65 + i)
);
// Commit.
await page.keyboard.press("Escape");
await page.waitForTimeout(10);
allPositions.push(
await page.$eval(getEditorSelector(i), el => {
const { x, y } = el.getBoundingClientRect();
return { x, y };
})
);
}
await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(10);
await dragAndDropAnnotation(page, rect.x + 161, rect.y + 126, 39, 74);
await page.waitForTimeout(10);
for (let i = 0; i < 10; i++) {
const pos = await page.$eval(getEditorSelector(i), el => {
const { x, y } = el.getBoundingClientRect();
return { x, y };
});
const oldPos = allPositions[i];
expect(Math.round(pos.x))
.withContext(`In ${browserName}`)
.toEqual(Math.round(oldPos.x + 39));
expect(Math.round(pos.y))
.withContext(`In ${browserName}`)
.toEqual(Math.round(oldPos.y + 74));
}
})
);
});
});
});

View file

@ -198,6 +198,7 @@ exports.serializeBitmapDimensions = serializeBitmapDimensions;
async function dragAndDropAnnotation(page, startX, startY, tX, tY) {
await page.mouse.move(startX, startY);
await page.mouse.down();
await page.waitForTimeout(10);
await page.mouse.move(startX + tX, startY + tY);
await page.mouse.up();
}