Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codeMirrorInstance prop to editors #240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zachkirsch
Copy link

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 79.836% when pulling 4c22705 on zachkirsch:codeMirrorInstance-prop into 3d49010 on scniro:master.

@zachkirsch
Copy link
Author

@scniro are you able to take a look here when you have a chance?

@davidwinter
Copy link

@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?

@zachkirsch
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants