mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
[text] Use the closest glyph to determine hit token
This commit is contained in:
@@ -72,11 +72,12 @@
|
|||||||
|
|
||||||
if (truncationTokenRange.location == NSNotFound) {
|
if (truncationTokenRange.location == NSNotFound) {
|
||||||
// The truncation string didn't specify a substring which should be highlighted, so we just highlight it all
|
// The truncation string didn't specify a substring which should be highlighted, so we just highlight it all
|
||||||
truncationTokenRange = { 0, self.attributes.truncationAttributedString.length };
|
truncationTokenRange = { 0, truncationAttributedString.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
truncationTokenRange.location += NSMaxRange(visibleRange);
|
truncationTokenRange.location += NSMaxRange(visibleRange);
|
||||||
|
|
||||||
|
__block CGFloat minDistance = CGFLOAT_MAX;
|
||||||
[self enumerateTextIndexesAtPosition:point usingBlock:^(NSUInteger index, CGRect glyphBoundingRect, BOOL *stop){
|
[self enumerateTextIndexesAtPosition:point usingBlock:^(NSUInteger index, CGRect glyphBoundingRect, BOOL *stop){
|
||||||
if (index >= truncationTokenRange.location) {
|
if (index >= truncationTokenRange.location) {
|
||||||
result = [[ASTextKitTextCheckingResult alloc] initWithType:ASTextKitTextCheckingTypeTruncation
|
result = [[ASTextKitTextCheckingResult alloc] initWithType:ASTextKitTextCheckingTypeTruncation
|
||||||
@@ -86,15 +87,14 @@
|
|||||||
NSRange range;
|
NSRange range;
|
||||||
NSDictionary *attributes = [attributedString attributesAtIndex:index effectiveRange:&range];
|
NSDictionary *attributes = [attributedString attributesAtIndex:index effectiveRange:&range];
|
||||||
ASTextKitEntityAttribute *entityAttribute = attributes[ASTextKitEntityAttributeName];
|
ASTextKitEntityAttribute *entityAttribute = attributes[ASTextKitEntityAttributeName];
|
||||||
if (entityAttribute) {
|
CGFloat distance = hypot(CGRectGetMidX(glyphBoundingRect) - point.x, CGRectGetMidY(glyphBoundingRect) - point.y);
|
||||||
|
if (entityAttribute && distance < minDistance) {
|
||||||
result = [[ASTextKitTextCheckingResult alloc] initWithType:ASTextKitTextCheckingTypeEntity
|
result = [[ASTextKitTextCheckingResult alloc] initWithType:ASTextKitTextCheckingTypeEntity
|
||||||
entityAttribute:entityAttribute
|
entityAttribute:entityAttribute
|
||||||
range:range];
|
range:range];
|
||||||
|
minDistance = distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result != nil) {
|
|
||||||
*stop = YES;
|
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user