onTextEdit method

  1. @override
TextEditingValue? onTextEdit(
  1. TextEditingValue value,
  2. TerminalUiInteraction terminal
)
override

Implementation

@override
TextEditingValue? onTextEdit(
    TextEditingValue value, TerminalUiInteraction terminal) {
  var inputText = value.text;
  // we just want to detect if a composing is going on and notify the terminal
  // about it
  if (value.composing.start != value.composing.end) {
    _composingString = inputText;
    terminal.updateComposingString(_composingString!);
    _lastEditingState = value;
    return null;
  }
  //when we reach this point the composing state is over
  if (_composingString != null) {
    _composingString = null;
    terminal.updateComposingString('');
  }

  //this is a hack to bypass some race condition in the input system
  //we just take the last rune if there are more than one as it sometimes
  //happens that the last value is still part of the new value

  if (_lastEditingState?.text.isNotEmpty == true) {
    if (inputText.length > _lastEditingState!.text.length) {
      inputText = inputText.substring(_lastEditingState!.text.length);
    }
  }

  if (inputText.isNotEmpty) {
    terminal.raiseOnInput(inputText);
  }

  _lastEditingState = value;

  if (value == TextEditingValue.empty || inputText == '') {
    return null;
  } else {
    return TextEditingValue.empty;
  }
}