getSpanForPositionVisitor method

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

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

Implementation

@override
InlineSpan getSpanForPositionVisitor(TextPosition position, Accumulator offset) {
  if (text == null) {
    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;
}