从光标位置获取当前行,并对其进行操作.这应该做(没有测试):
var doc = cm.getDoc();
var cursor = doc.getCursor(); // gets the line number in the cursor position
var line = doc.getLine(cursor.line); // get the line contents
var pos = { // create a new object to avoid mutation of the original selection
line: cursor.line,
ch: line.length - 1 // set the character position to the end of the line
}
doc.replaceRange('my new line of code\n', pos); // adds a new line
Run Code Online (Sandbox Code Playgroud)
这应该工作:
function appendTo(editor, line, text) {
editor.replaceRange(text, CodeMirror.Pos(line));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4943 次 |
| 最近记录: |