getLeadingTextBoundaryAt method
- int position
override
Returns the int representing the start position of the paragraph that
bounds the given position. The returned int is the position of the code unit
that follows the line terminator that encloses the desired paragraph.
Implementation
@override
int? getLeadingTextBoundaryAt(int position) {
if (position < 0 || _text.isEmpty) {
return null;
}
if (position >= _text.length) {
return _text.length;
}
if (position == 0) {
return 0;
}
int index = position;
if (index > 1 && _text.codeUnitAt(index) == 0x0A && _text.codeUnitAt(index - 1) == 0x0D) {
index -= 2;
} else if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
index -= 1;
}
while (index > 0) {
if (TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
return index + 1;
}
index -= 1;
}
return max(index, 0);
}