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;

  if (isComposingActive) {
    _selection = _commitCompositionAndRemapSelection(newSelection);
    selectionOnly = true;
    _isTyping = false;
    _imeProjectionDirty = true;
    requestImeReset?.call();
    notifyListeners();
    return;
  }

  _flushBuffer();

  _pendingSelectionReplacement = null;
  _selection = newSelection;
  selectionOnly = true;
  _isTyping = false;
  _imeProjectionDirty = true;

  _syncToConnection();

  notifyListeners();
}