splitAtCharacterIndex method
Splits this list of spans at the given character index
and returns one or two lists.
If index
is zero, or if index
is greater than the number of characters in these spans,
a list containing just this list is returned. If this list was split, an array of two lists
is returned, containing the two new lists.
Implementation
List<List<InlineSpan>> splitAtCharacterIndex(SplitAtIndex index) {
if (index.value == 0) return [this];
var i = 0;
for (final span in this) {
final result = span is SplittableMixin<InlineSpan>
? (span as SplittableMixin<InlineSpan>).splitAtIndex(index)
: span._splitAtIndex(index);
if (index.value == 0) {
if (result.length == 2) {
return [
[...take(i), result.first],
[result.last, ...skip(i + 1)],
];
} else if (result.length == 1) {
return [
[...take(i), result.first],
if (i + 1 < length) [...skip(i + 1)],
];
} else {
assert(false);
break;
}
}
i++;
}
return [this];
}