How to add new line programmatically in CodeMirror? -
i need insert new line next current line number in codemirror.
i viewed documentation didn't find appending content @ end of line.
please help. :(
get current line cursor position, , act on it. should (not tested):
var doc = cm.getdoc(); var cursor = doc.getcursor(); // gets line number in cursor position var line = doc.getline(cursor.line); // line contents var pos = { // create new object avoid mutation of original selection line: cursor.line, ch: line.length - 1 // set character position end of line } doc.replacerange('my new line of code\n', pos); // adds new line
Comments
Post a Comment