I am working on customizing the codemirror for my new language mode. As part of this new mode implementation, I am writing a new tool bar where user can select some text and
Final function to insert text at current cursor position in a performant way. Hope it helps.
function insertStringInTemplate(str) { var doc = editor_template.getDoc(); var cursor = doc.getCursor(); var pos = { line: cursor.line, ch: cursor.ch } doc.replaceRange(str, pos); }