Fix crash truncating a string of a node with a zero size

The crash happens in the placeholderImage of ASTextNode. The node is not visible in the time it try to get the `placeholderImage` and so the `visibleRange` has count 0 and a crash happens while accessing the first object of an empty array.
This commit is contained in:
Michael Schneider
2016-06-03 09:39:34 -07:00
parent 86deec4033
commit 19bb6519ed
8 changed files with 100 additions and 16 deletions

View File

@@ -262,3 +262,17 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
}
@end
@implementation ASTextKitRenderer (ASTextKitRendererConvenience)
- (NSRange)firstVisibleRange
{
std::vector<NSRange> visibleRanges = self.visibleRanges;
if (visibleRanges.size() > 0) {
return visibleRanges[0];
}
return NSMakeRange(NSNotFound, 0);
}
@end