Skip the web page close confirmation when crashed or in debug mode

This commit is contained in:
Keavon Chambers
2021-12-21 18:43:02 -08:00
parent 3b7a5548ae
commit 8f100b4f0a
2 changed files with 17 additions and 2 deletions

View File

@@ -160,6 +160,12 @@ export function createInputManager(editor: EditorState, container: HTMLElement,
};
const onBeforeUnload = (e: BeforeUnloadEvent) => {
// Skip the message if the editor crashed, since work is already lost
if (editor.instance.has_crashed()) return;
// Skip the message during development, since it's annoying when testing
if (process.env.NODE_ENV === "development") return;
const allDocumentsSaved = document.state.documents.reduce((acc, doc) => acc && doc.isSaved, true);
if (!allDocumentsSaved) {
e.returnValue = "Unsaved work will be lost if the web browser tab is closed. Close anyway?";