format method

Delta format(
  1. int index,
  2. int length,
  3. NotusAttribute attribute
)

Formats segment of this document with specified attribute.

Applies heuristic rules before modifying this document and produces a change event with its source set to ChangeSource.local.

Returns an instance of Delta actually composed into this document. The returned Delta may be empty in which case this document remains unchanged and no change event is published to the changes stream.

Implementation

Delta format(int index, int length, NotusAttribute attribute) {
  assert(index >= 0 && length >= 0);

  var change = Delta();

  final formatChange =
      heuristics.applyFormatRules(this, index, length, attribute);
  if (formatChange.isNotEmpty) {
    compose(formatChange, ChangeSource.local);
    change = change.compose(formatChange);
  }

  return change;
}