Skip to content

Commit

Permalink
[ASTextNode2] Refine implementation of link handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
appleguy committed Jul 3, 2017
1 parent 8e4ff4e commit 258ffe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## master

* Add your own contributions to the next release on the line below this with your name.
- [ASTextNode2] Add initial implementation for link handling. [Scott Goodson](https://github.com/appleguy) [#396](https://github.com/TextureGroup/Texture/pull/396)

##2.3.4
- [Yoga] Rewrite YOGA_TREE_CONTIGUOUS mode with improved behavior and cleaner integration [Scott Goodson](https://github.com/appleguy)
Expand Down
24 changes: 12 additions & 12 deletions Source/Private/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ - (id)_linkAttributeValueAtPoint:(CGPoint)point
{
ASDN::MutexLocker l(__instanceLock__);

// TODO: The copy and application of size shouldn't be required, but it is currently.
// See discussion in https://github.com/TextureGroup/Texture/pull/396
ASTextContainer *containerCopy = [_textContainer copy];
containerCopy.size = self.calculatedSize;
ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:containerCopy text:_attributedText];
Expand All @@ -506,30 +508,26 @@ - (id)_linkAttributeValueAtPoint:(CGPoint)point
}

NSRange effectiveRange = NSMakeRange(0, 0);
for (NSString *attributeName in self.linkAttributeNames) {
for (__strong NSString *attributeName in self.linkAttributeNames) {
id value = [self.attributedText attribute:attributeName atIndex:range.start.offset longestEffectiveRange:&effectiveRange inRange:clampedRange];
NSString *name = attributeName;
if (value == nil || name == nil) {
// Didn't find anything
if (value == nil) {
// Didn't find any links specified with this attribute.
continue;
}

// If highlighting, check with delegate first. If not implemented, assume YES.
if (highlighting
&& [_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)]
&& ![_delegate textNode:(ASTextNode *)self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
&& ![_delegate textNode:(ASTextNode *)self shouldHighlightLinkAttribute:attributeName value:value atPoint:point]) {
value = nil;
name = nil;
attributeName = nil;
}

if (value != nil || name != nil) {
*rangeOut = effectiveRange;
if (NSMaxRange(*rangeOut) > NSMaxRange(visibleRange)) {
(*rangeOut).length = MAX(NSMaxRange(visibleRange) - (*rangeOut).location, 0);
}
if (value != nil || attributeName != nil) {
*rangeOut = NSIntersectionRange(visibleRange, effectiveRange);

if (attributeNameOut != NULL) {
*attributeNameOut = name;
*attributeNameOut = attributeName;
}

return value;
Expand Down Expand Up @@ -737,6 +735,8 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
NSRange visibleRange = NSMakeRange(0, 0);
{
ASDN::MutexLocker l(__instanceLock__);
// TODO: The copy and application of size shouldn't be required, but it is currently.
// See discussion in https://github.com/TextureGroup/Texture/pull/396
ASTextContainer *containerCopy = [_textContainer copy];
containerCopy.size = self.calculatedSize;
ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:containerCopy text:_attributedText];
Expand Down

0 comments on commit 258ffe4

Please sign in to comment.