我正在使用羽毛笔编辑器。假设我有一个选择框,我可以从中选择值,以便可以将其插入到 quill 编辑器中。但我希望将值插入光标处,而不是内容的末尾或开头。
答案 0 :(得分:0)
给你,看看下面的代码和盒子演示:
https://codesandbox.io/s/hidden-brook-m2m80?file=/src/app/app.component.ts
绑定quill editor的引用
@ViewChild(QuillEditorComponent, { static: true })
editor: QuillEditorComponent;
获取光标位置并插入文本
onChangeOption(key: string) {
const index = this.editor.quillEditor?.getSelection()?.index; // get cursor position
if (index !== undefined) {
this.editor.quillEditor?.insertText(index, key); // insert text after the index
}
}
答案 1 :(得分:0)
//获取选择索引
var range = quill.getSelection();
//在光标处插入文本
quill.insertText(range.index, text, 'bold', true);