mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Change assumed value for text node highlighting delegate method to YES and don't consult it unless highlighting.
This commit is contained in:
@@ -245,7 +245,7 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {
|
|||||||
@param attribute The attribute that was tapped. Will not be nil.
|
@param attribute The attribute that was tapped. Will not be nil.
|
||||||
@param value The value of the tapped attribute.
|
@param value The value of the tapped attribute.
|
||||||
@param point The point within textNode, in textNode's coordinate system, that was touched to trigger a highlight.
|
@param point The point within textNode, in textNode's coordinate system, that was touched to trigger a highlight.
|
||||||
@discussion If not implemented, the default value is NO.
|
@discussion If not implemented, the default value is YES.
|
||||||
@return YES if the entity attribute should be a link, NO otherwise.
|
@return YES if the entity attribute should be a link, NO otherwise.
|
||||||
*/
|
*/
|
||||||
- (BOOL)textNode:(ASTextNode *)textNode shouldHighlightLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point;
|
- (BOOL)textNode:(ASTextNode *)textNode shouldHighlightLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point;
|
||||||
|
|||||||
@@ -394,13 +394,15 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
|
|||||||
return [self _linkAttributeValueAtPoint:point
|
return [self _linkAttributeValueAtPoint:point
|
||||||
attributeName:attributeNameOut
|
attributeName:attributeNameOut
|
||||||
range:rangeOut
|
range:rangeOut
|
||||||
inAdditionalTruncationMessage:NULL];
|
inAdditionalTruncationMessage:NULL
|
||||||
|
forHighlighting:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)_linkAttributeValueAtPoint:(CGPoint)point
|
- (id)_linkAttributeValueAtPoint:(CGPoint)point
|
||||||
attributeName:(out NSString **)attributeNameOut
|
attributeName:(out NSString **)attributeNameOut
|
||||||
range:(out NSRange *)rangeOut
|
range:(out NSRange *)rangeOut
|
||||||
inAdditionalTruncationMessage:(out BOOL *)inAdditionalTruncationMessageOut
|
inAdditionalTruncationMessage:(out BOOL *)inAdditionalTruncationMessageOut
|
||||||
|
forHighlighting:(BOOL)highlighting
|
||||||
{
|
{
|
||||||
ASTextKitRenderer *renderer = [self _renderer];
|
ASTextKitRenderer *renderer = [self _renderer];
|
||||||
NSRange visibleRange = renderer.visibleRanges[0];
|
NSRange visibleRange = renderer.visibleRanges[0];
|
||||||
@@ -453,10 +455,10 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if delegate implements optional method, if not assume NO.
|
// If highlighting, check with delegate first. If not implemented, assume YES.
|
||||||
// Should the text be highlightable/touchable?
|
if (highlighting
|
||||||
if (![_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)] ||
|
&& [_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)]
|
||||||
![_delegate textNode:self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
|
&& ![_delegate textNode:self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
|
||||||
value = nil;
|
value = nil;
|
||||||
name = nil;
|
name = nil;
|
||||||
}
|
}
|
||||||
@@ -758,7 +760,8 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
|
|||||||
id linkAttributeValue = [self _linkAttributeValueAtPoint:point
|
id linkAttributeValue = [self _linkAttributeValueAtPoint:point
|
||||||
attributeName:&linkAttributeName
|
attributeName:&linkAttributeName
|
||||||
range:&range
|
range:&range
|
||||||
inAdditionalTruncationMessage:&inAdditionalTruncationMessage];
|
inAdditionalTruncationMessage:&inAdditionalTruncationMessage
|
||||||
|
forHighlighting:YES];
|
||||||
|
|
||||||
NSUInteger lastCharIndex = NSIntegerMax;
|
NSUInteger lastCharIndex = NSIntegerMax;
|
||||||
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
|
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
|
||||||
@@ -787,7 +790,8 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
|
|||||||
id linkAttributeValue = [self _linkAttributeValueAtPoint:point
|
id linkAttributeValue = [self _linkAttributeValueAtPoint:point
|
||||||
attributeName:&linkAttributeName
|
attributeName:&linkAttributeName
|
||||||
range:&range
|
range:&range
|
||||||
inAdditionalTruncationMessage:&inAdditionalTruncationMessage];
|
inAdditionalTruncationMessage:&inAdditionalTruncationMessage
|
||||||
|
forHighlighting:YES];
|
||||||
|
|
||||||
NSUInteger lastCharIndex = NSIntegerMax;
|
NSUInteger lastCharIndex = NSIntegerMax;
|
||||||
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
|
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
|
||||||
@@ -838,7 +842,8 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
|
|||||||
[self _linkAttributeValueAtPoint:point
|
[self _linkAttributeValueAtPoint:point
|
||||||
attributeName:NULL
|
attributeName:NULL
|
||||||
range:&range
|
range:&range
|
||||||
inAdditionalTruncationMessage:NULL];
|
inAdditionalTruncationMessage:NULL
|
||||||
|
forHighlighting:YES];
|
||||||
|
|
||||||
if (!NSEqualRanges(_highlightRange, range)) {
|
if (!NSEqualRanges(_highlightRange, range)) {
|
||||||
[self _clearHighlightIfNecessary];
|
[self _clearHighlightIfNecessary];
|
||||||
|
|||||||
Reference in New Issue
Block a user