retain method

  1. @override
void retain(
  1. int index,
  2. int? len,
  3. Style? style
)
override

Implementation

@override
void retain(int index, int? len, Style? style) {
  if (style == null) {
    return;
  }
  final thisLength = length;

  final local = math.min(thisLength - index, len!);
  // If index is at newline character then this is a line/block style update.
  final isLineFormat = (index + local == thisLength) && 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 != thisLength);
    super.retain(index, local, style);
  }

  final remain = len - local;
  if (remain > 0) {
    assert(nextLine != null);
    nextLine!.retain(0, remain, style);
  }
}