我正在将Angular 7与主轴编辑器一起使用。 用例:我有羽毛笔编辑器,并且需要在双击任何按钮上添加一些文本,以获取双击的值,但无法获得光标在羽毛笔编辑器中的位置。
我尝试了(onContentChanged),(onEditorCreated)和(onSelectionChanged),还尝试了onFocus,因为我必须在一个模板中使用多个笔芯编辑器。
只需要在焦点编辑器上附加文本,而只需在光标位置上附加文本即可。
这是我的代码示例
<quill-editor #editor [maxLength]="maxLength"
[minLength]="minLength"
[modules]="quillConfig"
[(ngModel)]="text"
(onContentChanged)="contentchanged($event)"
(onEditorCreated)="editorCreated($event)"
[placeholder]="placeholder"
[readOnly]="readonly"
[required]="required"
[style]="{height: height}"
(onSelectionChanged)="onFocus($event)">
答案 0 :(得分:1)
您可以使用主轴编辑器的insertText方法执行此操作。这是在光标位置插入ABCD
的简单实现:
const selection = this.editor.getSelection(); // get position of cursor (index of selection)
this.editor.insertText(selection.index, 'ABCD'); // insert text into the cursor position