主轴编辑器中的光标位置

时间:2019-11-27 04:57:26

标签: angular angular7 quill 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)">

1 个答案:

答案 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

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

相关问题