From 59578969e3b3e72f3717dd4a80bb370256ca1cc0 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Tue, 30 Jul 2024 14:47:59 +0000 Subject: [PATCH] Clean up --- gui/src/app/FileEditor/TextEditor.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gui/src/app/FileEditor/TextEditor.tsx b/gui/src/app/FileEditor/TextEditor.tsx index 9c35964..a88edea 100644 --- a/gui/src/app/FileEditor/TextEditor.tsx +++ b/gui/src/app/FileEditor/TextEditor.tsx @@ -103,7 +103,7 @@ const TextEditor: FunctionComponent = ({ useEffect(() => { if (!editorInstance) return; - editorInstance.addAction({ + const disposable = editorInstance.addAction({ id: "save", label: "Save", keybindings: [KeyMod.CtrlCmd | KeyCode.KeyS], @@ -113,14 +113,18 @@ const TextEditor: FunctionComponent = ({ } }, }); + return () => { + disposable.dispose(); + }; }, [editorInstance, onSaveText, readOnly]); useEffect(() => { if (!editorInstance) return; if (!actions) return; - for (const action of actions) { - editorInstance.addAction(action); - } + const disposables = actions.map(editorInstance.addAction); + return () => { + disposables.forEach((d) => d.dispose()); + }; }, [actions, editorInstance]); const edited = useMemo(() => {