query method
Get a sublist of texts starting from start index
with the given length.
Implementation
EasyTextList query(int start, int length) {
final EasyTextList result = EasyTextList();
int offset = 0;
int remain = length;
// probably i can just use extractAt, but
// i prefer just making this manually
for (final EasyText text in this) {
if (offset + text.length <= start) {
offset += text.length;
continue;
}
if (remain <= 0) break;
final int localStart = math.max(0, start - offset);
final int localEnd = math.min(
text.length,
localStart + remain,
);
if (localEnd > localStart) {
result.add(
text.copyWith(text: text.between(localStart, localEnd)),
);
remain -= (localEnd - localStart);
}
offset += text.length;
}
return result;
}