Returns the text span that contains the given position in the text.
Source
TextSpan getSpanForPosition(TextPosition position) { assert(debugAssertIsValid()); TextAffinity affinity = position.affinity; int targetOffset = position.offset; int offset = 0; TextSpan result; visitTextSpan((TextSpan span) { assert(result == null); int endOffset = offset + span.text.length; if (targetOffset == offset && affinity == TextAffinity.downstream || targetOffset > offset && targetOffset < endOffset || targetOffset == endOffset && affinity == TextAffinity.upstream) { result = span; return false; } offset = endOffset; return true; }); return result; }