applyRule method

  1. @override
Delta? applyRule(
  1. Delta document,
  2. int index, {
  3. int? len,
  4. Object? data,
  5. Attribute? attribute,
})
override

Implementation

@override
Delta? applyRule(Delta document, int index,
    {int? len, Object? data, Attribute? attribute}) {
  if (data is! String || data != '\n') {
    return null;
  }

  final itr = DeltaIterator(document)..skip(index);
  final cur = itr.next();
  if (cur.data is! String || !(cur.data as String).startsWith('\n')) {
    return null;
  }

  Map<String, dynamic>? resetStyle;
  if (cur.attributes != null &&
      cur.attributes!.containsKey(Attribute.header.key)) {
    resetStyle = Attribute.header.toJson();
  }
  return Delta()
    ..retain(index + (len ?? 0))
    ..insert('\n', cur.attributes)
    ..retain(1, resetStyle)
    ..trim();
}