setInitialText method
void
setInitialText()
Sets the comment this controller is editing.
The comment is parsed for tags, and the text is formatted accordingly.
The backendToTaggable
function is used to convert the backend format of
a taggable to a taggable object. It takes the tag prefix and the backend
string as arguments and returns the taggable object.
Implementation
void setInitialText(
String initialText,
FutureOr<T?> Function(String prefix, String backendString)
backendToTaggable,
) async {
clear();
final StringBuffer tmpText = StringBuffer();
for (final String word in initialText.split(' ')) {
final tagPrefix =
tagStyles.keys.where((prefix) => word.startsWith(prefix)).firstOrNull;
if (tagPrefix == null) {
tmpText.write('$word ');
continue;
}
final backendTag = word.substring(tagPrefix.length);
final taggable = await backendToTaggable(tagPrefix, backendTag);
if (taggable == null) {
tmpText.write('$word ');
continue;
}
final frontendString = toFrontendConverter(taggable);
_tagsToTaggables[tagPrefix + frontendString] = (tagPrefix, taggable);
tmpText.write('$tagStartMarker$tagPrefix$frontendString$tagEndMarker ');
}
text = tmpText.toString().trimRight();
}