Skip to content

Commit

Permalink
Fix bug where tapping after a link selects the link to the left of it
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarvis committed Sep 19, 2014
1 parent 3c6977a commit 8eb6420
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions MFJLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,23 @@ - (void)longPress:(UILongPressGestureRecognizer *)sender
NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:location inTextContainer:textContainer];
NSUInteger characterIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex];

NSRange effectiveRange;
NSDictionary *attributes = [self.textStorage attributesAtIndex:characterIndex
effectiveRange:&effectiveRange];

self.linkRange = effectiveRange;
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.75
target:self
selector:@selector(timerFired:)
userInfo:attributes
repeats:NO];
CGRect boundingRect = [layoutManager boundingRectForGlyphRange:NSMakeRange(glyphIndex, 1)
inTextContainer:textContainer];

if (CGRectContainsPoint(boundingRect, location))
{
NSRange effectiveRange;
NSDictionary *attributes = [self.textStorage attributesAtIndex:characterIndex
effectiveRange:&effectiveRange];

self.linkRange = effectiveRange;
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.75
target:self
selector:@selector(timerFired:)
userInfo:attributes
repeats:NO];
}

}
else if ([sender state] == UIGestureRecognizerStateChanged)
{
Expand Down Expand Up @@ -373,6 +380,14 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive
NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:location inTextContainer:textContainer];
NSUInteger characterIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex];

CGRect boundingRect = [layoutManager boundingRectForGlyphRange:NSMakeRange(glyphIndex, 1)
inTextContainer:textContainer];

if (CGRectContainsPoint(boundingRect, location) == NO)
{
return NO;
}

NSRange effectiveRange;
NSDictionary *attributes = [self.textStorage attributesAtIndex:characterIndex
effectiveRange:&effectiveRange];
Expand Down

0 comments on commit 8eb6420

Please sign in to comment.