Keeping textArea and CodeMirror in sync

I’d like to be able to keep a textarea and the CodeMirror instance instantiated on it in sync (in terms of text content). I realize that will update the textarea from the current CodeMirror state, but what if I want to update CodeMirror to reflect the current content of the textarea? It seems like re-running fromTextArea() does the trick, but I’m concerned this could be a heavyweight operation and even possibly lead to memory leaks.

Any suggestions? Thanks in advance.

There’s no built-in functionality like this, but you can listen for events on both and use setValue to update the CodeMirror value. Just make sure you ignore CodeMirror “change” events that you yourself caused, to avoid infinite loops.