mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-16 10:14:03 +02:00
Merge pull request #20649 from calixteman/bug2015385
Ends the current drawing session when closing the tab (bug 2015385)
This commit is contained in:
commit
ae9fc13d8f
@ -963,6 +963,10 @@ class AnnotationEditorUIManager {
|
||||
},
|
||||
{ capture: true, signal }
|
||||
);
|
||||
window.addEventListener("beforeunload", this.#beforeUnload.bind(this), {
|
||||
capture: true,
|
||||
signal,
|
||||
});
|
||||
this.#addSelectionListener();
|
||||
this.#addDragAndDropListeners();
|
||||
this.#addKeyboardManager();
|
||||
@ -1398,6 +1402,11 @@ class AnnotationEditorUIManager {
|
||||
this.highlightSelection(methodOfCreation, /* comment */ true);
|
||||
}
|
||||
|
||||
#beforeUnload(e) {
|
||||
this.commitOrRemove();
|
||||
this.currentLayer?.endDrawingSession(/* isAborted = */ false);
|
||||
}
|
||||
|
||||
#displayFloatingToolbar() {
|
||||
const selection = document.getSelection();
|
||||
if (!selection || selection.isCollapsed) {
|
||||
|
||||
@ -17,6 +17,7 @@ import {
|
||||
awaitPromise,
|
||||
clearEditors,
|
||||
closePages,
|
||||
countStorageEntries,
|
||||
dragAndDrop,
|
||||
getAnnotationSelector,
|
||||
getEditors,
|
||||
@ -1236,3 +1237,43 @@ describe("Ink must update its color", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ink must committed when leaving the tab", () => {
|
||||
let pages;
|
||||
|
||||
beforeEach(async () => {
|
||||
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that the annotation storage is updated when leaving the tab", 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;
|
||||
await drawLine(page, x, y, x + 50, y + 50);
|
||||
|
||||
const count = await countStorageEntries(page);
|
||||
expect(count).withContext(`In ${browserName}`).toEqual(0);
|
||||
|
||||
// Trigger the beforeunload event to force auto-commit
|
||||
await page.evaluate(() => {
|
||||
window.dispatchEvent(new Event("beforeunload"));
|
||||
});
|
||||
|
||||
// Wait for the annotation to be committed to storage
|
||||
await waitForStorageEntries(page, 1);
|
||||
|
||||
const countAfter = await countStorageEntries(page);
|
||||
expect(countAfter).withContext(`In ${browserName}`).toEqual(1);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user