鹅毛笔编辑器中的光标位置

Rak*_*ngh 3 quill angular angular7 ngx-quill

我正在使用带有鹅毛笔编辑器的 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)">
Run Code Online (Sandbox Code Playgroud)

Ano*_*nta 7

您可以使用鹅毛笔编辑器的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
Run Code Online (Sandbox Code Playgroud)

完整示例: https: //stackblitz.com/edit/angular-ffkfhp