问题
I would like to reset all the contents of the Codemirror editor. Ideally, this should clear the textarea, remove all marks and clear the history.
What's the best way to achieve this?
回答1:
cm.setValue("");
cm.clearHistory();
// cm.clearGutter("gutterId"); if you have gutters
回答2:
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).
回答3:
Also, doing cm.setValue(newValue)
just sets content of the editor without deleting the CM instance. Doc
来源:https://stackoverflow.com/questions/16378355/how-to-reset-codemirror-editor