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 composing range in value provided by
  // ZefyrController 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;

  final shouldRemember = value.text != _lastKnownRemoteTextEditingValue!.text;
  _lastKnownRemoteTextEditingValue = actualValue;
  _textInputConnection!.setEditingState(actualValue);
  if (shouldRemember) {
    // Only keep track if text changed (selection changes are not relevant)
    _sentRemoteValues.add(actualValue);
  }
}