insertMention method

void insertMention(
  1. MentionObject mention
)

Insert a mention in the currently mentioning position

Implementation

void insertMention(MentionObject mention) {
  assert(isMentioning());

  final int mentionVisibleTextEnd =
      _mentionStartingIndex! + mention.displayName.length + 1;

  _cachedMentions.add(_TextMention(
      id: mention.id,
      display: mention.displayName,
      start: _mentionStartingIndex!,
      end: mentionVisibleTextEnd,
      syntax: _mentionSyntax!));

  final int mentionStart = _mentionStartingIndex!;
  final int mentionEnd = _mentionStartingIndex! + _mentionLength!;
  final String startChar = _mentionSyntax!.startingCharacter;

  cancelMentioning();

  _bGuardDeletion = true;
  text = text.replaceRange(
      mentionStart, mentionEnd, '$startChar${mention.displayName}');
  _bGuardDeletion = false;

  selection = TextSelection.collapsed(
      offset: mentionVisibleTextEnd, affinity: TextAffinity.upstream);

  _sortMentions();
}