Fix deadlock calling trailingRect on a ASTextNode

This commit is contained in:
Michael Schneider 2016-04-13 10:13:09 -07:00
parent 402c5fe25a
commit 91b6995987

View File

@ -333,6 +333,8 @@ static const CGFloat ASTextKitRendererTextCapHeightPadding = 1.3;
- (CGRect)trailingRect - (CGRect)trailingRect
{ {
__block CGRect trailingRect = CGRectNull; __block CGRect trailingRect = CGRectNull;
__block CGSize calculatedSize = CGSizeZero;
__block NSRange textRange = NSMakeRange(0, 0);
[self.context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) { [self.context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
CGSize calculatedSize = textContainer.size; CGSize calculatedSize = textContainer.size;
// If have an empty string, then our whole bounds constitute trailing space. // If have an empty string, then our whole bounds constitute trailing space.
@ -341,14 +343,15 @@ static const CGFloat ASTextKitRendererTextCapHeightPadding = 1.3;
return; return;
} }
// Take everything after our final character as trailing space. textRange = NSMakeRange([textStorage length] - 1, 1);
NSArray *finalRects = [self rectsForTextRange:NSMakeRange([textStorage length] - 1, 1) measureOption:ASTextKitRendererMeasureOptionLineHeight];
CGRect finalGlyphRect = [[finalRects lastObject] CGRectValue];
CGPoint origin = CGPointMake(CGRectGetMaxX(finalGlyphRect), CGRectGetMinY(finalGlyphRect));
CGSize size = CGSizeMake(calculatedSize.width - origin.x, calculatedSize.height - origin.y);
trailingRect = (CGRect){origin, size};
}]; }];
return trailingRect;
// Take everything after our final character as trailing space.
NSArray *finalRects = [self rectsForTextRange:textRange measureOption:ASTextKitRendererMeasureOptionLineHeight];
CGRect finalGlyphRect = [[finalRects lastObject] CGRectValue];
CGPoint origin = CGPointMake(CGRectGetMaxX(finalGlyphRect), CGRectGetMinY(finalGlyphRect));
CGSize size = CGSizeMake(calculatedSize.width - origin.x, calculatedSize.height - origin.y);
return (CGRect){origin, size};
} }
- (CGRect)frameForTextRange:(NSRange)textRange - (CGRect)frameForTextRange:(NSRange)textRange