apply method

  1. @override
Delta apply(
  1. Delta document,
  2. int index,
  3. String text

Applies heuristic rule to an insert operation on a document and returns resulting Delta.


Delta apply(Delta document, int index, String text) {
  if (text != '\n') return null;

  final iter = DeltaIterator(document);
  final before = iter.skip(index);
  final after =;
  if (isEdgeLineSplit(before, after)) return null;
  final result = Delta()..retain(index);
  if ('\n')) {
    // It is not allowed to combine line and inline styles in insert
    // operation containing line-break together with other characters.
    // The only scenario we get such operation is when the text is plain.
    // No attributes to apply so we simply create a new line.
    return result;
  // Continue looking for line-break.
  Map<String, dynamic> attributes;
  while (iter.hasNext) {
    final op =;
    final lf ='\n');
    if (lf >= 0) {
      attributes = op.attributes;
  result.insert('\n', attributes);
  return result;