insertTaggable method
Inserts a taggable into the text field at the current cursor position.
Insertion typically replaces any tag prompt with the taggable. The number
of characters to replace is given by charactersToReplace.
Implementation
void insertTaggable(String prefix, T taggable, int charactersToReplace) {
final tagStyle = tagStyles.where((style) => prefix == style.prefix).first;
final tag = Tag<T>(taggable: taggable, style: tagStyle);
final tagText = tag.toModifiedString(
toFrontendConverter,
toBackendConverter,
isFrontend: false,
);
_tagBackendFormatsToTaggables[tagText] = taggable;
final end = selection.baseOffset;
final start = end - charactersToReplace;
value = TextEditingValue(
text: text.replaceRange(start, end, tagText),
selection: TextSelection.collapsed(offset: start + tagText.length),
);
}