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 (attribute!.key != Attribute.link.key || len! > 0) {
    return null;
  }

  final delta = Delta();
  final itr = DeltaIterator(document);
  final before = itr.skip(index), after = itr.next();
  int? beg = index, retain = 0;
  if (before != null && before.hasAttribute(attribute.key)) {
    beg -= before.length!;
    retain = before.length;
  }
  if (after.hasAttribute(attribute.key)) {
    if (retain != null) retain += after.length!;
  }
  if (retain == 0) {
    return null;
  }

  delta
    ..retain(beg)
    ..retain(retain!, attribute.toJson());
  return delta;
}