calculateLine method
calculateLine taking soft wrapping into account, returns the total viewable lines and the real-line index for the given yoffset, as well as the virtual line offset.
Implementation
(int total, int ridx, int voffset) calculateLine(int yoffset) {
if (!softWrap) {
return (_lines.length, math.min(yoffset, _lines.length), 0);
}
final maxWidth = _maxWidth().toDouble();
if (maxWidth <= 0) return (0, 0, 0);
var total = 0;
var ridx = 0;
var voffset = 0;
for (var i = 0; i < _lines.length; i++) {
final line = _lines[i];
final lineWidth = Style.visibleLength(line);
final lineHeight = math.max(1, (lineWidth / maxWidth).ceil());
if (yoffset >= total && yoffset < total + lineHeight) {
ridx = i;
voffset = yoffset - total;
}
total += lineHeight;
}
if (yoffset >= total) {
ridx = _lines.length;
voffset = 0;
}
return (total, ridx, voffset);
}