我正在尝试通过以下方式替换在 CodeMirror v3 中选择的 token
var obj = editor.getTokenAt(currLine);
var currLine = editor.getCursor(true);
但似乎唯一的选择就是这样做
replaceRange
它考虑了新字符串和开始位置,但是当新字符串比原始字符串短或长时,就会发生奇怪的事情。
有什么更好的方法吗?
currLinereplace
似乎不适合我。
谢谢!
最佳答案
var pos = editor.getCursor() // or {line , ch };
var tok = editor.getTokenAt(pos);
editor.replaceRange("string", {line: pos.line , ch:tok.start},{line:pos.line , ch:tok.end});
关于javascript - 替换 CodeMirror token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13487266/