Open zachkirsch opened 3 years ago
@scniro are you able to take a look here when you have a chance?
@zachkirsch depending on what you're trying to achieve, I was able to use a React ref and pass that into the react-codemirror2
component, for example:
const editorInput = useRef(null);
...
<ReactCodeMirror ref={inputref} options={options} value={content} onBeforeChange={handleChange}/>
Then elsewhere in my code, I could access the codemirror instance like so:
editorInput.current.editor.focus();
You may be able to do the same in order to setup extensions?
Thanks @davidwinter! The feature I wanted to use was CodeMirrorInstance.defineExtension
, which I couldn't figure out how to do with this package. But I actually figured out a workaround yesterday for our use case (custom search bar) so I'm no longer blocked on this!
This PR adds a
codeMirrorInstance
prop to the editor, as inspired by the same prop in react-codemirror.I'm trying to migrate my company from react-codemirror to react-codemirror2, but without this prop (or another way of defining codemirror extensions) I'm not yet able to.