getAttributedRange method
Returns the range about offset
, which is attributed with all given attributions
.
attributions
must not be empty.
Implementation
SpanRange getAttributedRange(Set<Attribution> attributions, int offset) {
if (attributions.isEmpty) {
throw Exception('getAttributedRange requires a non empty set of attributions');
}
int? maxStartMarkerOffset;
int? minEndMarkerOffset;
for (final attribution in attributions) {
if (!hasAttributionAt(offset, attribution: attribution)) {
throw Exception(
'Tried to get the attributed range of ($attribution) at offset "$offset" but the given attribution does not exist at that offset.');
}
int startMarkerOffset = _getStartingMarkerAtOrBefore(offset, attribution: attribution)!.offset;
int endMarkerOffset = _getEndingMarkerAtOrAfter(offset, attribution: attribution)!.offset;
if (maxStartMarkerOffset == null || startMarkerOffset > maxStartMarkerOffset) {
maxStartMarkerOffset = startMarkerOffset;
}
if (minEndMarkerOffset == null || endMarkerOffset < minEndMarkerOffset) {
minEndMarkerOffset = endMarkerOffset;
}
}
// Note: maxStartMarkerOffset and minEndMarkerOffset are non-null because we verified
// that all desired attributions are present at the given offset.
return SpanRange(
maxStartMarkerOffset!,
minEndMarkerOffset!,
);
}