业务场景:在代码编辑器外点击按钮,向代码编辑器内的光标处新增一条拼接好的信息。
getCursor方法:
官方文档:
doc.getCursor(?start: string) → {line, ch}
Retrieve one end of the primary selection. start is an optional string indicating which end of the selection to return. It may be “from”, “to”, “head” (the side of the selection that moves when you press shift+arrow), or “anchor” (the fixed side of the selection). Omitting the argument is the same as passing “head”. A {line, ch} object will be returned.粗暴翻译:
能获取到光标所在的位置,返回一个{line, ch}对象replaceRange方法:
官方文档:
doc.replaceRange(replacement: string, from: {line, ch}, to: {line, ch}, ?origin: string)
Replace the part of the document between from and to with the given string. from and to must be {line, ch} objects. to can be left off to simply insert the string at