insertTextAtSelection method

void insertTextAtSelection(
  1. String text, {
  2. String source = 'user',
})

Implementation

void insertTextAtSelection(String text, {String source = 'user'}) {
  final editor = _quill;
  if (editor == null) {
    return;
  }
  final range = editor.getSelection(focus: true) ??
      (_lastSelection == null
          ? null
          : LiQuillBridgeSelection(
              index: _lastSelection!.index,
              length: _lastSelection!.length,
            ));
  final index = range?.index ?? 0;
  final length = range?.length ?? 0;
  if (length > 0) {
    editor.deleteText(index, length, source);
  }
  editor.insertText(index, text, source);
  editor.setSelection(index + text.length, 0, 'silent');
}