formatText method

void formatText(
  1. int index,
  2. int length,
  3. NotusAttribute attribute
)

Implementation

void formatText(int index, int length, NotusAttribute attribute) {
  final change = document.format(index, length, attribute);
  // _lastChangeSource = ChangeSource.local;
  final source = ChangeSource.local;

  if (length == 0 && _insertionToggleableStyleKeys.contains(attribute.key)) {
    // Add the attribute to our toggledStyle. It will be used later upon insertion.
    _toggledStyles = toggledStyles.put(attribute);
  }

  // Transform selection against the composed change and give priority to
  // the change. This is needed in cases when format operation actually
  // inserts data into the document (e.g. embeds).
  final base = change.transformPosition(_selection.baseOffset);
  final extent = change.transformPosition(_selection.extentOffset);
  final adjustedSelection =
      _selection.copyWith(baseOffset: base, extentOffset: extent);
  if (_selection != adjustedSelection) {
    _updateSelectionSilent(adjustedSelection, source: source);
  }
  notifyListeners();
}