Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/display/editor/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class HighlightEditor extends AnnotationEditor {
}
}

/** @inheritdoc */
translateInPage(x, y) {}

/** @inheritdoc */
get toolbarPosition() {
return this.#lastPoint;
Expand Down
63 changes: 62 additions & 1 deletion test/integration/highlight_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
closePages,
getEditorSelector,
getSerialized,
kbBigMoveLeft,
kbBigMoveUp,
kbSelectAll,
loadAndWait,
scrollIntoView,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
})
);
});
});
});