How to reset Codemirror editor?

Also, doing cm.setValue(newValue) just sets content of the editor without deleting the CM instance. Doc


var codemirror = $('#YOUR_TEXTAREA_ID').nextAll('.CodeMirror')[0].CodeMirror;
codemirror.getDoc().setValue("");

If you don't want to kill the CodeMirror instance, just change the entire document holding the text, data on markers etc.

This can be done by calling cm.swapDoc(doc: CodeMirror.Doc).


cm.setValue("");
cm.clearHistory();
// cm.clearGutter("gutterId"); if you have gutters

Tags:

Codemirror