format method

EasyTextChange format(
  1. EasyAttributeStyles style, [
  2. bool overrideStylesIfEmpty = false,
  3. bool ignoreMerge = false
])

Formats this EasyText and optimizes it with adjacent EasyTexts if needed.

Implementation

EasyTextChange format(
  EasyAttributeStyles style, [
  bool overrideStylesIfEmpty = false,
  bool ignoreMerge = false,
]) {
  final EasyAttributeStyles oldStyles =
      // we prefer just avoid making deep clones when no required
      !overrideStylesIfEmpty ? EasyAttributeStyles.empty() : style.deepClone;
  overrideStylesIfEmpty && style.isEmpty
      ? styles.clearAll()
      : applyStyle(style);
  if (!ignoreMerge) tryMerge();
  if (overrideStylesIfEmpty && style.isEmpty) {
    return EasyTextChange(
      start: 0,
      length: length,
      delta: Delta()..retain(length, oldStyles.invert().toJson()),
      inverted: Delta()..retain(length, oldStyles.toJson()),
    );
  }
  return EasyTextChange(
    start: 0,
    length: length,
    delta: Delta()..retain(length, style.toJson()),
    inverted: Delta()..retain(length, style.invert().toJson()),
  );
}