insertText method
Inserts the longest whole-grapheme prefix that fits maxLength. Returns the number of UTF-16 code units inserted.
Implementation
int insertText(String value) {
final inserted = _truncate(
value, maxLength == null ? value.length : maxLength! - length);
if (inserted.isEmpty) return 0;
final position = _cursorPosition + inserted.length;
_replace('$textBeforeCursor$inserted$textAfterCursor', position,
roundUp: true);
return inserted.length;
}