mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[text] Fix crash when highlighted range exceeds truncation range
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user