1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

Introduce a generic selectEditors helper function

This replaces the various copies of this logic with a single helper that
we template for each editor type, similar to what we already do for the
`switchToEditor` helper.
This commit is contained in:
Tim van der Meij 2025-02-23 18:49:14 +01:00
parent 060ef0e15e
commit f155b69c07
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
5 changed files with 16 additions and 28 deletions

View file

@ -37,7 +37,6 @@ import {
kbModifierDown,
kbModifierUp,
kbRedo,
kbSelectAll,
kbUndo,
loadAndWait,
moveEditor,
@ -45,6 +44,7 @@ import {
pasteFromClipboard,
scrollIntoView,
selectEditor,
selectEditors,
switchToEditor,
unselectEditor,
waitForAnnotationEditorLayer,
@ -57,12 +57,7 @@ import {
} from "./test_utils.mjs";
import { PNG } from "pngjs";
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".freeTextEditor:not(.selectedEditor)")
);
};
const selectAll = selectEditors.bind(null, "freeText");
const clearAll = async page => {
await selectAll(page);

View file

@ -27,10 +27,10 @@ import {
kbFocusNext,
kbFocusPrevious,
kbSave,
kbSelectAll,
kbUndo,
loadAndWait,
scrollIntoView,
selectEditors,
setCaretAt,
switchToEditor,
unselectEditor,
@ -47,12 +47,7 @@ import path from "path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".highlightEditor:not(.selectedEditor)")
);
};
const selectAll = selectEditors.bind(null, "highlight");
const switchToHighlight = switchToEditor.bind(null, "Highlight");

View file

@ -24,12 +24,12 @@ import {
getSerialized,
isCanvasWhite,
kbRedo,
kbSelectAll,
kbUndo,
loadAndWait,
moveEditor,
scrollIntoView,
selectEditor,
selectEditors,
switchToEditor,
waitForAnnotationModeChanged,
waitForNoElement,
@ -40,12 +40,7 @@ import {
waitForTimeout,
} from "./test_utils.mjs";
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".inkEditor.disabled:not(.selectedEditor)")
);
};
const selectAll = selectEditors.bind(null, "ink");
const clearAll = async page => {
await selectAll(page);

View file

@ -32,13 +32,13 @@ import {
isVisible,
kbBigMoveDown,
kbBigMoveRight,
kbSelectAll,
kbUndo,
loadAndWait,
paste,
pasteFromClipboard,
scrollIntoView,
selectEditor,
selectEditors,
serializeBitmapDimensions,
switchToEditor,
unselectEditor,
@ -57,12 +57,7 @@ import { PNG } from "pngjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".stampEditor:not(.selectedEditor)")
);
};
const selectAll = selectEditors.bind(null, "stamp");
const clearAll = async page => {
await selectAll(page);

View file

@ -809,6 +809,13 @@ async function switchToEditor(name, page, disable = false) {
await awaitPromise(modeChangedHandle);
}
async function selectEditors(name, page) {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(`.${name}Editor:not(.selectedEditor)`)
);
}
function waitForNoElement(page, selector) {
return page.waitForFunction(
sel => !document.querySelector(sel),
@ -927,6 +934,7 @@ export {
pasteFromClipboard,
scrollIntoView,
selectEditor,
selectEditors,
serializeBitmapDimensions,
setCaretAt,
switchToEditor,