setSelectionImmediately method

void setSelectionImmediately(
  1. TextSelection newSelection
)

Implementation

void setSelectionImmediately(TextSelection newSelection) {
  if (_selection == newSelection) return;

  _flushBuffer();

  final textLength = text.length;
  final clampedBase = newSelection.baseOffset.clamp(0, textLength);
  final clampedExtent = newSelection.extentOffset.clamp(0, textLength);
  newSelection = newSelection.copyWith(
    baseOffset: clampedBase,
    extentOffset: clampedExtent,
  );

  _selection = newSelection;
  selectionOnly = true;
  _isTyping = false;

  if (connection != null && connection!.attached) {
    _lastSentText = text;
    _lastSentSelection = newSelection;
    connection!.setEditingState(
      TextEditingValue(text: _lastSentText!, selection: newSelection),
    );
  }

  notifyListeners();
}