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 clearEditors 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:52:19 +01:00
parent f155b69c07
commit acc5a2153a
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
4 changed files with 13 additions and 21 deletions

View file

@ -15,6 +15,7 @@
import {
awaitPromise,
clearEditors,
closePages,
copy,
copyToClipboard,
@ -59,13 +60,7 @@ import { PNG } from "pngjs";
const selectAll = selectEditors.bind(null, "freeText");
const clearAll = async page => {
await selectAll(page);
await page.keyboard.down("Control");
await page.keyboard.press("Backspace");
await page.keyboard.up("Control");
await waitForStorageEntries(page, 0);
};
const clearAll = clearEditors.bind(null, "freeText");
const commit = async page => {
await page.keyboard.press("Escape");

View file

@ -15,6 +15,7 @@
import {
awaitPromise,
clearEditors,
closePages,
dragAndDrop,
getAnnotationSelector,
@ -42,11 +43,7 @@ import {
const selectAll = selectEditors.bind(null, "ink");
const clearAll = async page => {
await selectAll(page);
await page.keyboard.press("Backspace");
await waitForStorageEntries(page, 0);
};
const clearAll = clearEditors.bind(null, "ink");
const commit = async page => {
await page.keyboard.press("Escape");

View file

@ -17,6 +17,7 @@ import {
applyFunctionToEditor,
awaitPromise,
cleanupEditing,
clearEditors,
clearInput,
closePages,
copy,
@ -38,7 +39,6 @@ import {
pasteFromClipboard,
scrollIntoView,
selectEditor,
selectEditors,
serializeBitmapDimensions,
switchToEditor,
unselectEditor,
@ -47,7 +47,6 @@ import {
waitForEntryInStorage,
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTimeout,
} from "./test_utils.mjs";
import { fileURLToPath } from "url";
@ -57,13 +56,7 @@ import { PNG } from "pngjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const selectAll = selectEditors.bind(null, "stamp");
const clearAll = async page => {
await selectAll(page);
await page.keyboard.press("Backspace");
await waitForStorageEntries(page, 0);
};
const clearAll = clearEditors.bind(null, "stamp");
const waitForImage = async (page, selector) => {
await page.waitForSelector(`${selector} canvas`);

View file

@ -816,6 +816,12 @@ async function selectEditors(name, page) {
);
}
async function clearEditors(name, page) {
await selectEditors(name, page);
await page.keyboard.press("Backspace");
await waitForStorageEntries(page, 0);
}
function waitForNoElement(page, selector) {
return page.waitForFunction(
sel => !document.querySelector(sel),
@ -888,6 +894,7 @@ export {
applyFunctionToEditor,
awaitPromise,
cleanupEditing,
clearEditors,
clearInput,
closePages,
closeSinglePage,