addSelectionEnter method

void addSelectionEnter({
  1. bool mustAdd = false,
})

光标后回车

Implementation

void addSelectionEnter({bool mustAdd = false}) {
  final String content = text;
  if (content.isNotEmpty || mustAdd) {
    final int selectionPosition = selection.baseOffset;
    if (selectionPosition == text.length) {
      addEnter();
      return;
    }
    if (selectionPosition >= 0 && selectionPosition <= text.length - 1) {
      final firstText = content.substring(0, selectionPosition);
      final lastText = content.substring(selectionPosition, text.length);
      text = '$firstText\n$lastText';
      selection = TextSelection.collapsed(offset: selectionPosition + 1);
    }
  }
}