我用的是笔编辑。假设我有一个选择框,可以从中选择值,以便将其插入到quill编辑器中。但是我希望将值插入到游标处,而不是在内容的末尾或开头。
发布于 2021-05-16 09:29:11
//获取选择的索引
var range = quill.getSelection();
//插入光标处的文本
quill.insertText(range.index,文本,‘粗体’,真);
发布于 2021-05-15 22:30:59
在这里,请查看下面的代码框演示:
https://codesandbox.io/s/hidden-brook-m2m80?file=/src/app/app.component.ts
绑定笔编辑器的引用
@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
}
}
https://stackoverflow.com/questions/67550807
复制相似问题