selection property

TextSelection get selection

The current text selection in the editor.

For a cursor with no selection, TextSelection.isCollapsed will be true.

Implementation

TextSelection get selection => _selection;
set selection (TextSelection newSelection)

Sets the current text selection.

Setting this property will update the selection and notify listeners. For a collapsed cursor, use TextSelection.collapsed(offset: pos).

Implementation

set selection(TextSelection newSelection) {
  if (_selection == newSelection) return;

  _flushBuffer();

  _selection = newSelection;
  selectionOnly = true;

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

  notifyListeners();
}