diff --git a/packages/core/src/mods/settingBar/components/code/index.tsx b/packages/core/src/mods/settingBar/components/code/index.tsx index eb0231e..4240b93 100644 --- a/packages/core/src/mods/settingBar/components/code/index.tsx +++ b/packages/core/src/mods/settingBar/components/code/index.tsx @@ -81,6 +81,7 @@ interface IEditorModalProps { const EditModal: React.FC = (props) => { const { visible, title, value, onSave, onOk, onCancel } = props; const [code, setCode] = useState(value); + const [editorInst, setEditorInst] = useState(); const [codeRunVisible, setCodeRunVisible] = useState(false); // life @@ -93,6 +94,15 @@ const EditModal: React.FC = (props) => { setCode(''); } }, [visible]); + useEffect(() => { + if(editorInst) { + // NOTE: how to add command(https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandalonecodeeditor.html#addcommand) + editorInst.addCommand(KeyMod.CtrlCmd | KeyCode.KEY_S, () => { + onSave(editorInst.getValue()); + message.success('保存成功', 1); + }); + } + }, [editorInst, onSave]); // events const onEditOk = (): void => { @@ -112,11 +122,7 @@ const EditModal: React.FC = (props) => { } }; const onEditorDidMount: EditorDidMount = (getEditorValue, editor) => { - // doc: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandalonecodeeditor.html#addcommand - editor.addCommand(KeyMod.CtrlCmd | KeyCode.KEY_S, () => { - onSave(getEditorValue()); - message.success('保存成功', 1); - }); + setEditorInst(editor); }; return (