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?
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) .
The easiest way to set up CodeMirror is via <script> tag from a CDN. You can also bundle the CodeMirror npm module, but for the sake of example let's just use a CDN. Just make sure you include both the JavaScript and CSS files, otherwise your editor won't look right.
CodeMirror is a code editor component for the web. It can be used in websites to implement a text input field with support for many editing features, and has a rich programming interface to allow further extension.
var codemirror = $('#YOUR_TEXTAREA_ID').nextAll('.CodeMirror')[0].CodeMirror;
codemirror.getDoc().setValue("");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With