Merge pull request #20649 from calixteman/bug2015385

Ends the current drawing session when closing the tab (bug 2015385)
This commit is contained in:
calixteman 2026-02-13 08:27:16 +01:00 committed by GitHub
commit ae9fc13d8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 0 deletions

View File

@ -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) {

View File

@ -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);
})
);
});
});