insert method

void insert({
  1. required AttributedText newText,
  2. required int insertIndex,
  3. TextSelection? newSelection,
  4. TextRange? newComposingRegion,
})

Inserts newText, starting at the given insertIndex.

The selection is updated to newSelection, if provided, otherwise a best-guess attempt is made to adjust the selection based on an insertion action.

The composingRegion is updated to newComposingRegion, if provided, otherwise the composingRegion is set to TextRange.empty.

Implementation

void insert({
  required AttributedText newText,
  required int insertIndex,
  TextSelection? newSelection,
  TextRange? newComposingRegion,
}) {
  final updatedText = _text.insert(
    textToInsert: newText,
    startOffset: insertIndex,
  );

  final updatedSelection = newSelection ??
      _moveSelectionForInsertion(
        selection: _selection,
        insertIndex: insertIndex,
        newTextLength: newText.length,
      );

  update(
    text: updatedText,
    selection: updatedSelection,
    composingRegion: newComposingRegion ?? TextRange.empty,
  );
}