}
return builder.create();
}
public StyleSpans<S> getStyleSpans(int from, int to) {
Position start = navigator.offsetToPosition(from, Forward);
Position end = to == from
? start
: start.offsetBy(to - from, Backward);
int startSegIdx = start.getMajor();
int endSegIdx = end.getMajor();
int n = endSegIdx - startSegIdx + 1;
StyleSpansBuilder<S> builder = new StyleSpansBuilder<>(n);
if(startSegIdx == endSegIdx) {
StyledText<S> seg = segments.get(startSegIdx);
builder.add(seg.getStyle(), to - from);
} else {
StyledText<S> startSeg = segments.get(startSegIdx);
builder.add(startSeg.getStyle(), startSeg.length() - start.getMinor());
for(int i = startSegIdx + 1; i < endSegIdx; ++i) {
StyledText<S> seg = segments.get(i);
builder.add(seg.getStyle(), seg.length());
}
StyledText<S> endSeg = segments.get(endSegIdx);
builder.add(endSeg.getStyle(), end.getMinor());
}
return builder.create();
}