mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-05-17 00:06:44 +08:00
fix truncater method to only return the truncater.
This commit is contained in:
@@ -156,7 +156,7 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
|
||||
}];
|
||||
}
|
||||
|
||||
[self truncater];
|
||||
[[self truncater] truncate];
|
||||
|
||||
// Force glyph generation and layout, which may not have happened yet (and isn't triggered by
|
||||
// -usedRectForTextContainer:).
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
_context = context;
|
||||
_truncationAttributedString = truncationAttributedString;
|
||||
_avoidTailTruncationSet = avoidTailTruncationSet;
|
||||
|
||||
[self _truncate];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -153,7 +151,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_truncate
|
||||
- (void)truncate
|
||||
{
|
||||
[_context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
NSUInteger originalStringLength = textStorage.length;
|
||||
|
||||
@@ -33,4 +33,9 @@
|
||||
truncationAttributedString:(NSAttributedString *)truncationAttributedString
|
||||
avoidTailTruncationSet:(NSCharacterSet *)avoidTailTruncationSet;
|
||||
|
||||
/**
|
||||
* Actually do the truncation.
|
||||
*/
|
||||
- (void)truncate;
|
||||
|
||||
@end
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
|
||||
truncationAttributedString:nil
|
||||
avoidTailTruncationSet:nil];
|
||||
[tailTruncater truncate];
|
||||
XCTAssert(NSEqualRanges(textKitVisibleRange, tailTruncater.visibleRanges[0]));
|
||||
}
|
||||
|
||||
@@ -71,6 +72,7 @@
|
||||
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
|
||||
truncationAttributedString:[self _simpleTruncationAttributedString]
|
||||
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@""]];
|
||||
[tailTruncater truncate];
|
||||
__block NSString *drawnString;
|
||||
[context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
drawnString = textStorage.string;
|
||||
@@ -95,7 +97,7 @@
|
||||
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
|
||||
truncationAttributedString:[self _simpleTruncationAttributedString]
|
||||
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
|
||||
(void)tailTruncater;
|
||||
[tailTruncater truncate];
|
||||
__block NSString *drawnString;
|
||||
[context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
drawnString = textStorage.string;
|
||||
@@ -120,8 +122,7 @@
|
||||
ASTextKitTailTruncater *tailTruncater = [[ASTextKitTailTruncater alloc] initWithContext:context
|
||||
truncationAttributedString:[self _simpleTruncationAttributedString]
|
||||
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
|
||||
// So Xcode doesn't yell at me for an unused var...
|
||||
(void)tailTruncater;
|
||||
[tailTruncater truncate];
|
||||
__block NSString *drawnString;
|
||||
[context performBlockWithLockedTextKitComponents:^(NSLayoutManager *layoutManager, NSTextStorage *textStorage, NSTextContainer *textContainer) {
|
||||
drawnString = textStorage.string;
|
||||
@@ -144,9 +145,9 @@
|
||||
layoutManagerDelegate:nil
|
||||
textStorageCreationBlock:nil];
|
||||
|
||||
XCTAssertNoThrow([[ASTextKitTailTruncater alloc] initWithContext:context
|
||||
XCTAssertNoThrow([[[ASTextKitTailTruncater alloc] initWithContext:context
|
||||
truncationAttributedString:[self _simpleTruncationAttributedString]
|
||||
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@"."]]);
|
||||
avoidTailTruncationSet:[NSCharacterSet characterSetWithCharactersInString:@"."]] truncate]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user