that may not be saved dialog
This commit is contained in:
parent
de9b7a7350
commit
bac5dc97dd
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue