updateEditingValue method

  1. @override
void updateEditingValue(
  1. TextEditingValue value
)
inherited

Requests that this client update its editing state to the given value.

The new value is treated as user input and thus may subject to input formatting.

Implementation

@override
void updateEditingValue(TextEditingValue value) {
  if (!shouldCreateInputConnection) {
    return;
  }

  if (_lastKnownRemoteTextEditingValue == value) {
    // There is no difference between this value and the last known value.
    return;
  }

  // Check if only composing range changed.
  if (_lastKnownRemoteTextEditingValue!.text == value.text &&
      _lastKnownRemoteTextEditingValue!.selection == value.selection) {
    // This update only modifies composing range. Since we don't keep track
    // of composing range we just need to update last known value here.
    // This check fixes an issue on Android when it sends
    // composing updates separately from regular changes for text and
    // selection.
    _lastKnownRemoteTextEditingValue = value;
    return;
  }

  final effectiveLastKnownValue = _lastKnownRemoteTextEditingValue!;
  _lastKnownRemoteTextEditingValue = value;
  final oldText = effectiveLastKnownValue.text;
  final text = value.text;
  final cursorPosition = value.selection.extentOffset;
  final diff = getDiff(oldText, text, cursorPosition);
  if (diff.deleted.isEmpty && diff.inserted.isEmpty) {
    widget.configurations.controller
        .updateSelection(value.selection, ChangeSource.local);
  } else {
    widget.configurations.controller.replaceText(
      diff.start,
      diff.deleted.length,
      diff.inserted,
      value.selection,
    );
  }
}