diff --git a/src/app.tsx b/src/app.tsx index a86dc60..b9612d0 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -157,6 +157,20 @@ function AppContent() { } }, [amaranthSource, amaranthVersion]); + const runCodeRef = useRef(runCode); + runCodeRef.current = runCode; + + const amaranthSourceEditorActions = React.useMemo(() => [ + { + id: 'amaranth-playground.run', + label: 'Run Code', + keybindings: [ + monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, + ], + run: runCodeRef.current, + } + ], [runCodeRef]); + function tabAndPanel({ key, title, titleStyle = {}, content }) { return [ {title}, @@ -307,16 +321,7 @@ function AppContent() { title: 'Amaranth Source', content: diff --git a/src/monaco.tsx b/src/monaco.tsx index ebb084f..b769f6e 100644 --- a/src/monaco.tsx +++ b/src/monaco.tsx @@ -52,7 +52,6 @@ export function Editor({ state, actions = [], padding, focus = false }: EditorPr readOnly: state.readOnly, padding, }); - actions.forEach(action => editorRef.current?.addAction(action)); const resizeObserver = new ResizeObserver(events => editorRef.current?.layout()); resizeObserver.observe(containerRef.current!); editorRef.current.restoreViewState(state.viewState); @@ -63,6 +62,15 @@ export function Editor({ state, actions = [], padding, focus = false }: EditorPr resizeObserver.disconnect(); editorRef.current?.dispose(); }; + }, []); + + useEffect(() => { + if (!editorRef.current) + return; + const disposables = actions.map(action => editorRef.current!.addAction(action)); + return () => { + disposables.forEach(disposable => disposable.dispose()); + }; }, [actions]); return
;