deleteSelectionLastChar method

void deleteSelectionLastChar()

删除光标最后一个字符

Implementation

void deleteSelectionLastChar() {
  final String content = text;
  if (content.isNotEmpty) {
    final int selectionPosition = selection.baseOffset;
    if (selectionPosition == text.length) {
      deleteLastChar();
      return;
    }
    if (selectionPosition > 0 && selectionPosition <= text.length - 1) {
      final firstText = content.substring(0, selectionPosition - 1);
      final lastText = content.substring(selectionPosition, text.length);
      text = firstText + lastText;
      selection = TextSelection.collapsed(offset: selectionPosition - 1);
    }
  }
}