joinChar function

InlineSpan joinChar(
  1. InlineSpan value,
  2. Accumulator offset,
  3. String char
)

join char into text

Implementation

InlineSpan joinChar(
  InlineSpan value,
  Accumulator offset,
  String char,
) {
  late InlineSpan output;
  String? actualText;

  bool deleteAll = false;
  if (value is SpecialInlineSpanBase) {
    final SpecialInlineSpanBase base = value as SpecialInlineSpanBase;
    actualText = base.actualText;
    deleteAll = base.deleteAll;
  } else {
    deleteAll = false;
  }
  if (value is TextSpan) {
    List<InlineSpan>? children;
    final int start = offset.value;
    String? text = value.text;
    actualText ??= text;
    if (actualText != null) {
      actualText = actualText.joinChar();
      offset.increment(actualText.length);
    }

    if (text != null) {
      text = text.joinChar();
    }

    if (value.children != null) {
      children = <InlineSpan>[];
      for (final InlineSpan child in value.children!) {
        children.add(joinChar(child, offset, char));
      }
    }

    if (value is BackgroundTextSpan) {
      output = BackgroundTextSpan(
        background: value.background,
        clipBorderRadius: value.clipBorderRadius,
        paintBackground: value.paintBackground,
        text: text ?? '',
        actualText: actualText,
        start: start,
        style: value.style,
        recognizer: value.recognizer,
        deleteAll: deleteAll,
        semanticsLabel: value.semanticsLabel,
      );
    } else {
      output = SpecialTextSpan(
        text: text ?? '',
        actualText: actualText,
        children: children,
        start: start,
        style: value.style,
        recognizer: value.recognizer,
        deleteAll: deleteAll,
        semanticsLabel: value.semanticsLabel,
      );
    }
  } else if (value is WidgetSpan) {
    output = ExtendedWidgetSpan(
      child: value.child,
      start: offset.value,
      alignment: value.alignment,
      style: value.style,
      baseline: value.baseline,
      actualText: actualText,
    );

    offset.increment(actualText?.length ?? 1);
  } else {
    output = value;
  }

  return output;
}