From c5e634eaea44a2e6d6eb15da543d86aff101ef00 Mon Sep 17 00:00:00 2001 From: Sebastien Thiebaud Date: Thu, 10 Apr 2014 12:12:15 -0700 Subject: [PATCH] Fix #65 --- STTweetLabel/STTweetLabel.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/STTweetLabel/STTweetLabel.m b/STTweetLabel/STTweetLabel.m index 54fa6be..dbd796a 100644 --- a/STTweetLabel/STTweetLabel.m +++ b/STTweetLabel/STTweetLabel.m @@ -439,7 +439,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (!CGRectContainsPoint(_textView.frame, touchLocation)) return; - int charIndex = (int)[self charIndexAtLocation:[[touches anyObject] locationInView:_textView]]; + NSUInteger charIndex = [self charIndexAtLocation:[[touches anyObject] locationInView:_textView]]; [_rangesOfHotWords enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSRange range = [[obj objectForKey:@"range"] rangeValue]; @@ -454,7 +454,12 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - (NSUInteger)charIndexAtLocation:(CGPoint)touchLocation { NSUInteger glyphIndex = [_layoutManager glyphIndexForPoint:touchLocation inTextContainer:_textView.textContainer]; - return [_layoutManager characterIndexForGlyphAtIndex:glyphIndex]; + CGRect boundingRect = [_layoutManager boundingRectForGlyphRange:NSMakeRange(glyphIndex, 1) inTextContainer:_textView.textContainer]; + + if (CGRectContainsPoint(boundingRect, touchLocation)) + return [_layoutManager characterIndexForGlyphAtIndex:glyphIndex]; + else + return -1; } @end