admin管理员组文章数量:1327945
I am using quill editor. suppose i have a select box where i can select value from it, so that it can be inserted into the quill editor. But I want the value to be inserted at the cursor, instead of at the end or beginning of the content.
I am using quill editor. suppose i have a select box where i can select value from it, so that it can be inserted into the quill editor. But I want the value to be inserted at the cursor, instead of at the end or beginning of the content.
Share Improve this question asked May 15, 2021 at 20:07 Adharsh ChottuAdharsh Chottu 1452 gold badges5 silver badges20 bronze badges 1- Hi there. Try adding more code into your question so that people can better understand your case. – Nisanth Reddy Commented May 16, 2021 at 4:11
2 Answers
Reset to default 4//to get the index of selection
var range = quill.getSelection();
//to insert the text at cursor
quill.insertText(range.index, text, 'bold', true);
Here you are, check out the codesandbox demo below:
https://codesandbox.io/s/hidden-brook-m2m80?file=/src/app/app.ponent.ts
Bind the reference of quill editor
@ViewChild(QuillEditorComponent, { static: true })
editor: QuillEditorComponent;
Get the cursor position and insert text
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
}
}
本文标签: javascriptQuill editorinsert content in quill editor at the cursorStack Overflow
版权声明:本文标题:javascript - Quill editor - insert content in quill editor at the cursor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225084a2436163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论