deleteCharacter method

void deleteCharacter()

Implementation

void deleteCharacter() {
  String text = textEditingController.text;
  TextSelection selection = textEditingController.selection;

  if (selection.isCollapsed) {
    int cursorPosition = selection.baseOffset;
    if (cursorPosition <= 0 || cursorPosition > text.length) {
      return;
    }

    int start = cursorPosition;
    int end = cursorPosition;

    if (start > 0 && text[start - 1] == ']') {
      start = _findEmojiStart(text, start);
      if (start >= 0 && _isValidEmoji(text, start, end)) {
        _deleteText(text, start, end);
        return;
      }
    }

    start = cursorPosition;
    if (start > 0) {
      int deleteLength = _isUTF16(text, cursorPosition - 2) ? 2 : 1;
      start -= deleteLength;
      _deleteText(text, start, end);
    }
  } else {
    _deleteText(text, selection.start, selection.end);
  }
}