updateRemoteValueIfNeeded method

void updateRemoteValueIfNeeded()
inherited

Updates remote value based on current state of document and selection.

This method may not actually send an update to native side if it thinks remote value is up to date or identical.

Implementation

void updateRemoteValueIfNeeded() {
  if (!hasConnection) {
    return;
  }

  final value = textEditingValue;

  // Since we don't keep track of the composing range in value provided
  // by the Controller we need to add it here manually before comparing
  // with the last known remote value.
  // It is important to prevent excessive remote updates as it can cause
  // race conditions.
  final actualValue = value.copyWith(
    composing: _lastKnownRemoteTextEditingValue!.composing,
  );

  if (actualValue == _lastKnownRemoteTextEditingValue) {
    return;
  }

  _lastKnownRemoteTextEditingValue = actualValue;
  _textInputConnection!.setEditingState(
    // Set composing to (-1, -1), otherwise an exception will be thrown if
    // the values are different.
    actualValue.copyWith(composing: const TextRange(start: -1, end: -1)),
  );
}