How to reset Codemirror editor?

[亡魂溺海] 提交于 2019-12-09 16:32:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!