From bbb63875817f22334dc7fecceb08d97e12de0a01 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Sun, 24 Dec 2023 22:21:41 +0100 Subject: [PATCH] Make sure saveFunction() is called when the page is unloaded --- src/editor/editor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/editor/editor.js b/src/editor/editor.js index 9f518be..6578c03 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -86,6 +86,13 @@ export class HeynoteEditor { ], }) + // make sure saveFunction is called when page is unloaded + if (saveFunction) { + window.addEventListener("beforeunload", () => { + saveFunction(this.getContent()) + }) + } + this.view = new EditorView({ state: state, parent: element,