How to reset Codemirror Editor?

I would like to reset all the contents of the Codemirror editor. Ideally, this should clear the text box, remove all marks and clear the history.

What is the best way to achieve this?

+6
source share
3 answers
cm.setValue(""); cm.clearHistory(); // cm.clearGutter("gutterId"); if you have gutters 
+12
source

If you don't want to kill an instance of CodeMirror, just change the entire document containing the text, marker data, etc.

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

+1
source

In addition, executing cm.setValue(newValue) simply sets the contents of the editor without deleting the CM instance. Doc

+1
source

Source: https://habr.com/ru/post/944289/


All Articles