currentTextEditingValue property
The current state of the TextEditingValue held by this client.
Implementation
@override
TextEditingValue? get currentTextEditingValue {
if (defaultTargetPlatform == TargetPlatform.macOS) {
return _currentPlatformValue;
}
final text = _getCurrentFragmentText() ?? '';
final doc = _document;
if (doc == null) {
return TextEditingValue(
text: text,
selection: const TextSelection.collapsed(offset: 0),
);
}
final cursor = doc.cursor;
final isSingleFragSelection =
!cursor.isCollapsed && cursor.anchorId == cursor.focusId;
final isMultiFragSelection =
!cursor.isCollapsed && cursor.anchorId != cursor.focusId;
final offset = _getCursorOffsetInFragment();
final TextSelection selection;
if (isSingleFragSelection) {
selection = TextSelection(
baseOffset: cursor.anchorOffset.clamp(0, text.length),
extentOffset: cursor.focusOffset.clamp(0, text.length),
);
} else if (isMultiFragSelection) {
selection = TextSelection(baseOffset: 0, extentOffset: text.length);
} else {
selection = TextSelection.collapsed(offset: offset);
}
return TextEditingValue(
text: text,
selection: selection,
composing: state.isComposing && state.composingRange.isValid
? state.composingRange
: TextRange.empty,
);
}