Skip to content

Commit

Permalink
Merge pull request #18425 from calixteman/bug1879104
Browse files Browse the repository at this point in the history
[Editor] Make editor toolbars usable whatever their z-index (bug 1879104)
  • Loading branch information
calixteman authored Jul 11, 2024
2 parents acc70ce + 9a64749 commit df5bc54
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 26 deletions.
116 changes: 90 additions & 26 deletions test/integration/highlight_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
kbUndo,
loadAndWait,
scrollIntoView,
setCaretAt,
switchToEditor,
waitForSerialized,
} from "./test_utils.mjs";
Expand Down Expand Up @@ -1043,19 +1044,12 @@ describe("Highlight Editor", () => {
`${getEditorSelector(0)}:not(.selectedEditor)`
);

await page.evaluate(() => {
const text =
"Dynamic languages such as JavaScript are more difficult to com-";
for (const el of document.querySelectorAll(
`.page[data-page-number="${1}"] > .textLayer > span`
)) {
if (el.textContent === text) {
window.getSelection().setPosition(el.firstChild, 1);
break;
}
}
});

await setCaretAt(
page,
1,
"Dynamic languages such as JavaScript are more difficult to com-",
1
);
await page.keyboard.press("ArrowUp");
const [text, offset] = await page.evaluate(() => {
const selection = window.getSelection();
Expand All @@ -1073,19 +1067,12 @@ describe("Highlight Editor", () => {
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);

await page.evaluate(() => {
const text =
"Dynamic languages such as JavaScript are more difficult to com-";
for (const el of document.querySelectorAll(
`.page[data-page-number="${1}"] > .textLayer > span`
)) {
if (el.textContent === text) {
window.getSelection().setPosition(el.firstChild, 15);
break;
}
}
});

await setCaretAt(
page,
1,
"Dynamic languages such as JavaScript are more difficult to com-",
15
);
await page.keyboard.down("Shift");
await page.keyboard.press("ArrowDown");
await page.keyboard.up("Shift");
Expand Down Expand Up @@ -1702,4 +1689,81 @@ describe("Highlight Editor", () => {
);
});
});

describe("Use a toolbar overlapping an other highlight", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait(
"tracemonkey.pdf",
".annotationEditorLayer",
null,
null,
{
highlightEditorColors:
"yellow=#FFFF00,green=#00FF00,blue=#0000FF,pink=#FF00FF,red=#FF0000",
}
);
});

afterAll(async () => {
await closePages(pages);
});

it("must check that the toolbar is usable", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);

await setCaretAt(
page,
1,
"Dynamic languages such as JavaScript are more difficult to com-",
0
);
await page.keyboard.down("Shift");
for (let i = 0; i < 3; i++) {
await page.keyboard.press("ArrowDown");
}
await page.keyboard.up("Shift");

const editorSelector = getEditorSelector(0);
await page.waitForSelector(editorSelector);

await setCaretAt(
page,
1,
"handle all possible type combinations at runtime. We present an al-",
0
);
await page.keyboard.down("Shift");
for (let i = 0; i < 3; i++) {
await page.keyboard.press("ArrowDown");
}
await page.keyboard.up("Shift");
await page.waitForSelector(getEditorSelector(1));

const rect = await getRect(page, editorSelector);
const x = rect.x + rect.width / 2;
const y = rect.y + rect.height / 2;
await page.mouse.click(x, y);

await page.waitForSelector(
`${editorSelector} .editToolbar button.colorPicker`
);

await page.click(`${editorSelector} .editToolbar button.colorPicker`);
await page.waitForSelector(
`${editorSelector} .editToolbar button[title = "Green"]`
);
await page.click(
`${editorSelector} .editToolbar button[title = "Green"]`
);
await page.waitForSelector(
`.page[data-page-number = "1"] svg.highlight[fill = "#00FF00"]`
);
})
);
});
});
});
19 changes: 19 additions & 0 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,24 @@ async function hover(page, selector) {
await page.mouse.move(rect.x + rect.width / 2, rect.y + rect.height / 2);
}

async function setCaretAt(page, pageNumber, text, position) {
await page.evaluate(
(pageN, string, pos) => {
for (const el of document.querySelectorAll(
`.page[data-page-number="${pageN}"] > .textLayer > span`
)) {
if (el.textContent === string) {
window.getSelection().setPosition(el.firstChild, pos);
break;
}
}
},
pageNumber,
text,
position
);
}

const modifier = isMac ? "Meta" : "Control";
async function kbCopy(page) {
await page.keyboard.down(modifier);
Expand Down Expand Up @@ -713,6 +731,7 @@ export {
pasteFromClipboard,
scrollIntoView,
serializeBitmapDimensions,
setCaretAt,
switchToEditor,
waitForAnnotationEditorLayer,
waitForAnnotationModeChanged,
Expand Down
4 changes: 4 additions & 0 deletions web/annotation_editor_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
font-size: calc(100px * var(--scale-factor));
transform-origin: 0 0;
cursor: auto;

.selectedEditor {
z-index: 100000 !important;
}
}

.annotationEditorLayer.waiting {
Expand Down

0 comments on commit df5bc54

Please sign in to comment.