retain method
Implementation
@override
void retain(int index, int? len, Style? style) {
if (style == null) {
return;
}
final length = this.length;
final local = math.min(length - index, len!);
// If index is at newline character then this is a line/block style update.
final isLineFormat = (index + local == length) && local == 1;
if (isLineFormat) {
assert(
style.values.every((attr) =>
attr.scope == AttributeScope.block ||
attr.scope == AttributeScope.ignore),
'It is not allowed to apply inline attributes to line itself.');
_format(style);
} else {
// Otherwise forward to children as it's an inline format update.
assert(style.values.every((attr) =>
attr.scope == AttributeScope.inline ||
attr.scope == AttributeScope.ignore));
assert(index + local != length);
super.retain(index, local, style);
}
final remain = len - local;
if (remain > 0) {
assert(nextLine != null);
nextLine!.retain(0, remain, style);
}
}