insert method

bool insert(
  1. String char
)

Inserts a character at the cursor position.

Returns true if the character was inserted (respects maxLength).

Implementation

bool insert(String char) {
  if (char.isEmpty) return false;
  if (maxLength != null && _buffer.length >= maxLength!) return false;

  final before = text.substring(0, _cursorPosition);
  final after = text.substring(_cursorPosition);

  _buffer.clear();
  _buffer.write(before);
  _buffer.write(char);
  _buffer.write(after);

  _cursorPosition += char.length;
  return true;
}