parent
308ca2a16f
commit
4acc086292
@ -820,14 +820,14 @@ class AnnotationEditorLayer {
|
|||||||
this.#currentEditorType.startDrawing(this, this.#uiManager, false, event);
|
this.#currentEditorType.startDrawing(this, this.#uiManager, false, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
endDrawingSession() {
|
endDrawingSession(isAborted = false) {
|
||||||
if (!this.#drawingAC) {
|
if (!this.#drawingAC) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
this.#drawingAC.abort();
|
this.#drawingAC.abort();
|
||||||
this.#drawingAC = null;
|
this.#drawingAC = null;
|
||||||
this.#uiManager.disableUserSelect(false);
|
this.#uiManager.disableUserSelect(false);
|
||||||
this.#currentEditorType.endDrawing();
|
return this.#currentEditorType.endDrawing(isAborted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -739,13 +739,13 @@ class DrawingEditor extends AnnotationEditor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.endDrawing();
|
this.endDrawing(/* isAborted = */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static endDrawing() {
|
static endDrawing(isAborted) {
|
||||||
const parent = this._currentParent;
|
const parent = this._currentParent;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
parent.toggleDrawing(true);
|
parent.toggleDrawing(true);
|
||||||
parent.cleanUndoStack(AnnotationEditorParamsType.DRAW_STEP);
|
parent.cleanUndoStack(AnnotationEditorParamsType.DRAW_STEP);
|
||||||
@ -756,20 +756,31 @@ class DrawingEditor extends AnnotationEditor {
|
|||||||
scale,
|
scale,
|
||||||
} = parent;
|
} = parent;
|
||||||
|
|
||||||
parent.createAndAddNewEditor({ offsetX: 0, offsetY: 0 }, false, {
|
const editor = parent.createAndAddNewEditor(
|
||||||
drawId: this._currentDrawId,
|
{ offsetX: 0, offsetY: 0 },
|
||||||
drawOutlines: this._currentDraw.getOutlines(
|
false,
|
||||||
pageWidth * scale,
|
{
|
||||||
pageHeight * scale,
|
drawId: this._currentDrawId,
|
||||||
scale,
|
drawOutlines: this._currentDraw.getOutlines(
|
||||||
this._INNER_MARGIN
|
pageWidth * scale,
|
||||||
),
|
pageHeight * scale,
|
||||||
drawingOptions: this._currentDrawingOptions,
|
scale,
|
||||||
mustBeCommitted: true,
|
this._INNER_MARGIN
|
||||||
});
|
),
|
||||||
} else {
|
drawingOptions: this._currentDrawingOptions,
|
||||||
parent.drawLayer.remove(this._currentDrawId);
|
mustBeCommitted: !isAborted,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this._cleanup();
|
||||||
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parent.drawLayer.remove(this._currentDrawId);
|
||||||
|
this._cleanup();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static _cleanup() {
|
||||||
this._currentDrawId = -1;
|
this._currentDrawId = -1;
|
||||||
this._currentDraw = null;
|
this._currentDraw = null;
|
||||||
this._currentDrawingOptions = null;
|
this._currentDrawingOptions = null;
|
||||||
|
|||||||
@ -2088,11 +2088,16 @@ class AnnotationEditorUIManager {
|
|||||||
*/
|
*/
|
||||||
delete() {
|
delete() {
|
||||||
this.commitOrRemove();
|
this.commitOrRemove();
|
||||||
if (!this.hasSelection) {
|
const drawingEditor = this.currentLayer?.endDrawingSession(
|
||||||
|
/* isAborted = */ true
|
||||||
|
);
|
||||||
|
if (!this.hasSelection && !drawingEditor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const editors = [...this.#selectedEditors];
|
const editors = drawingEditor
|
||||||
|
? [drawingEditor]
|
||||||
|
: [...this.#selectedEditors];
|
||||||
const cmd = () => {
|
const cmd = () => {
|
||||||
for (const editor of editors) {
|
for (const editor of editors) {
|
||||||
editor.remove();
|
editor.remove();
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import {
|
|||||||
loadAndWait,
|
loadAndWait,
|
||||||
scrollIntoView,
|
scrollIntoView,
|
||||||
switchToEditor,
|
switchToEditor,
|
||||||
|
waitForNoElement,
|
||||||
waitForSerialized,
|
waitForSerialized,
|
||||||
waitForStorageEntries,
|
waitForStorageEntries,
|
||||||
} from "./test_utils.mjs";
|
} from "./test_utils.mjs";
|
||||||
@ -567,4 +568,48 @@ describe("Ink Editor", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Can delete the drawing in progress and undo the deletion", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must check that the color has been changed", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
await switchToInk(page);
|
||||||
|
|
||||||
|
const rect = await getRect(page, ".annotationEditorLayer");
|
||||||
|
|
||||||
|
const x = rect.x + 20;
|
||||||
|
const y = rect.y + 20;
|
||||||
|
const clickHandle = await waitForPointerUp(page);
|
||||||
|
await page.mouse.move(x, y);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(x + 50, y + 50);
|
||||||
|
await page.mouse.up();
|
||||||
|
await awaitPromise(clickHandle);
|
||||||
|
|
||||||
|
const drawSelector = `.canvasWrapper svg.draw path[d]:not([d=""])`;
|
||||||
|
await page.waitForSelector(drawSelector);
|
||||||
|
|
||||||
|
await page.keyboard.press("Backspace");
|
||||||
|
|
||||||
|
const editorSelector = getEditorSelector(0);
|
||||||
|
await waitForNoElement(page, drawSelector);
|
||||||
|
await waitForNoElement(page, editorSelector);
|
||||||
|
|
||||||
|
await kbUndo(page);
|
||||||
|
await page.waitForSelector(editorSelector, { visible: true });
|
||||||
|
await page.waitForSelector(drawSelector);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -773,6 +773,14 @@ async function switchToEditor(name, page, disable = false) {
|
|||||||
await awaitPromise(modeChangedHandle);
|
await awaitPromise(modeChangedHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function waitForNoElement(page, selector) {
|
||||||
|
return page.waitForFunction(
|
||||||
|
sel => !document.querySelector(sel),
|
||||||
|
{},
|
||||||
|
selector
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
applyFunctionToEditor,
|
applyFunctionToEditor,
|
||||||
awaitPromise,
|
awaitPromise,
|
||||||
@ -826,6 +834,7 @@ export {
|
|||||||
waitForAnnotationModeChanged,
|
waitForAnnotationModeChanged,
|
||||||
waitForEntryInStorage,
|
waitForEntryInStorage,
|
||||||
waitForEvent,
|
waitForEvent,
|
||||||
|
waitForNoElement,
|
||||||
waitForPageRendered,
|
waitForPageRendered,
|
||||||
waitForSandboxTrip,
|
waitForSandboxTrip,
|
||||||
waitForSelectedEditor,
|
waitForSelectedEditor,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user