getSpanForPositionVisitor method

  1. @override
InlineSpan? getSpanForPositionVisitor(
  1. TextPosition position,
  2. Accumulator offset
)
override

Returns the text span that contains the given position in the text.

Implementation

@override
InlineSpan? getSpanForPositionVisitor(TextPosition position, Accumulator offset) {
  final String? text = this.text;
  if (text == null || text.isEmpty) {
    return null;
  }
  final TextAffinity affinity = position.affinity;
  final int targetOffset = position.offset;
  final int endOffset = offset.value + text.length;

  if (offset.value == targetOffset && affinity == TextAffinity.downstream ||
      offset.value < targetOffset && targetOffset < endOffset ||
      endOffset == targetOffset && affinity == TextAffinity.upstream) {
    return this;
  }
  offset.increment(text.length);
  return null;
}