Confirm when the browser window is closed and there is unsaved work (#397)

* - browser confirmation on page exit
- prompt to save a document when closed will only trigger when unsaved

* add back select document for close prompt

* - name -> displayname
- add preventPropigation to middle click
This commit is contained in:
mfish33
2021-12-04 16:49:52 -08:00
committed by Keavon Chambers
parent 5f248cd176
commit 9904021744
6 changed files with 56 additions and 12 deletions
+9
View File
@@ -1,6 +1,7 @@
import { toggleFullscreen } from "@/utilities/fullscreen";
import { dialogIsVisible, dismissDialog, submitDialog } from "@/utilities/dialog";
import { panicProxy } from "@/utilities/panic-proxy";
import documents from "./documents";
const wasm = import("@/../wasm/pkg").then(panicProxy);
@@ -125,6 +126,14 @@ export async function onWindowResize() {
if (boundsOfViewports.length > 0) (await wasm).bounds_of_viewports(data);
}
export function onBeforeUnload(event: BeforeUnloadEvent) {
const allDocumentsSaved = documents.documents.reduce((acc, doc) => doc.isSaved && acc, true);
if (!allDocumentsSaved) {
event.returnValue = "Unsaved work will be lost if the web browser tab is closed. Close anyway?";
event.preventDefault();
}
}
export function makeModifiersBitfield(e: MouseEvent | KeyboardEvent): number {
return Number(e.ctrlKey) | (Number(e.shiftKey) << 1) | (Number(e.altKey) << 2);
}