[Editor] Avoid to move a non-draggable editor with the keyboard

This commit is contained in:
Calixte Denizet 2024-01-16 20:21:50 +01:00
parent 9c377922ef
commit 70a9d8f3bc
2 changed files with 65 additions and 1 deletions

View File

@ -109,6 +109,9 @@ class HighlightEditor extends AnnotationEditor {
}
}
/** @inheritdoc */
translateInPage(x, y) {}
/** @inheritdoc */
get toolbarPosition() {
return this.#lastPoint;

View File

@ -17,6 +17,8 @@ import {
closePages,
getEditorSelector,
getSerialized,
kbBigMoveLeft,
kbBigMoveUp,
kbSelectAll,
loadAndWait,
scrollIntoView,
@ -30,6 +32,12 @@ const selectAll = async page => {
);
};
const getXY = (page, selector) =>
page.evaluate(sel => {
const bbox = document.querySelector(sel).getBoundingClientRect();
return `${bbox.x}::${bbox.y}`;
}, selector);
const getSpanRectFromText = (page, pageNumber, text) => {
return page.evaluate(
(number, content) => {
@ -352,7 +360,7 @@ describe("Highlight Editor", () => {
await closePages(pages);
});
it("must be correctly serialized", async () => {
it("must check that we can use the keyboard to select a color", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.click("#editorHighlight");
@ -427,4 +435,57 @@ describe("Highlight Editor", () => {
);
});
});
describe("Text highlights aren't draggable", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait(
"tracemonkey.pdf",
".annotationEditorLayer",
null,
null,
{ highlightEditorColors: "red=#AB0000" }
);
});
afterAll(async () => {
await closePages(pages);
});
it("must check that a text highlight don't move when arrows are pressed", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.click("#editorHighlight");
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
const rect = await getSpanRectFromText(page, 1, "Abstract");
const x = rect.x + rect.width / 2;
const y = rect.y + rect.height / 2;
await page.mouse.click(x, y, { count: 2 });
await page.waitForSelector(`${getEditorSelector(0)}`);
await page.waitForSelector(
`.page[data-page-number = "1"] svg.highlightOutline.selected`
);
await page.focus(getEditorSelector(0));
const xy = await getXY(page, getEditorSelector(0));
for (let i = 0; i < 5; i++) {
await kbBigMoveLeft(page);
}
expect(await getXY(page, getEditorSelector(0)))
.withContext(`In ${browserName}`)
.toEqual(xy);
for (let i = 0; i < 5; i++) {
await kbBigMoveUp(page);
}
expect(await getXY(page, getEditorSelector(0)))
.withContext(`In ${browserName}`)
.toEqual(xy);
})
);
});
});
});