that may not be saved dialog

This commit is contained in:
Maze Winther 2026-01-23 23:53:18 +01:00
parent de9b7a7350
commit bac5dc97dd
2 changed files with 17 additions and 0 deletions

View File

@ -117,6 +117,19 @@ export function EditorProvider({ projectId, children }: EditorProviderProps) {
}
function EditorRuntimeBindings() {
const editor = useEditor();
useEffect(() => {
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
if (!editor.save.getIsDirty()) return;
event.preventDefault();
(event as unknown as { returnValue: string }).returnValue = "";
};
window.addEventListener("beforeunload", handleBeforeUnload);
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
}, [editor]);
useEditorActions();
useKeybindingsListener();
return null;

View File

@ -62,6 +62,10 @@ export class SaveManager {
await this.saveNow();
}
getIsDirty(): boolean {
return this.hasPendingSave || this.isSaving;
}
private queueSave(): void {
if (this.isSaving) return;
if (this.saveTimer) {