Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #92 from SebastienThiebaud/area-surrounding-bad-index
Browse files Browse the repository at this point in the history
Fix #65
  • Loading branch information
Sebastien C. Thiebaud committed Apr 10, 2014
2 parents c8c44db + c5e634e commit 42a3e0e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions STTweetLabel/STTweetLabel.m
Expand Up @@ -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];
Expand All @@ -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

0 comments on commit 42a3e0e

Please sign in to comment.