insert method
void
insert({
- required AttributedText newText,
- required int insertIndex,
- TextSelection? newSelection,
- 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,
);
}