[text] Fix crash when highlighted range exceeds truncation range

This commit is contained in:
yury
2016-01-26 22:37:44 +03:00
parent 1514d23d33
commit a0b7254213
2 changed files with 21 additions and 4 deletions

View File

@@ -27,9 +27,8 @@ static const CGFloat ASTextKitRendererTextCapHeightPadding = 1.3;
{
__block NSArray *textRects = @[];
[self.context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
BOOL textRangeIsValid = (NSMaxRange(textRange) <= [textStorage length]);
ASDisplayNodeCAssertTrue(textRangeIsValid);
if (!textRangeIsValid) {
NSRange clampedRange = NSIntersectionRange(textRange, NSMakeRange(0, [textStorage length]));
if (clampedRange.location == NSNotFound || clampedRange.length == 0) {
return;
}
@@ -41,7 +40,7 @@ static const CGFloat ASTextKitRendererTextCapHeightPadding = 1.3;
NSString *string = textStorage.string;
NSRange totalGlyphRange = [layoutManager glyphRangeForCharacterRange:textRange actualCharacterRange:NULL];
NSRange totalGlyphRange = [layoutManager glyphRangeForCharacterRange:clampedRange actualCharacterRange:NULL];
[layoutManager enumerateLineFragmentsForGlyphRange:totalGlyphRange usingBlock:^(CGRect rect,
CGRect usedRect,