import { observer } from 'mobx-react-lite'; import React, { useRef } from 'react'; import { useRootStore } from '../RootStore'; export const EditorArea = observer(() => { const { editorStore } = useRootStore(); const { CodeMirror } = editorStore.chunk || {}; const fallbackTextarea = useRef(null); if (!CodeMirror) { return ( ); } const textarea = fallbackTextarea.current; if (textarea) { editorStore.setInitialSelection( textarea.selectionStart, textarea.selectionEnd, document.activeElement === textarea, ); } return ( editorStore.editorDidMount(editor)} editorWillUnmount={() => editorStore.editorWillUnmount()} onBeforeChange={(_editor, _data, value) => editorStore.updateValue(value)} onChange={() => editorStore.reportChanged()} /> ); });