Skip to content

Commit

Permalink
Fix where the highlight is made. This fixes highlights that span mult…
Browse files Browse the repository at this point in the history
…iple lines because the highlight range was not being calculated correctly for subsequent lines.
  • Loading branch information
mattjgalloway committed Oct 10, 2013
1 parent c64d174 commit 5d65bee
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions OHAttributedLabel/Source/OHAttributedLabel.m
Expand Up @@ -664,16 +664,15 @@ -(void)drawActiveLinkHighlightForRect:(CGRect)rect
continue; // with next run
}

// Fix for issue #136
CFRange fullRunRange = CTRunGetStringRange(run);

CFIndex startActiveLinkInRun = (CFIndex)activeLinkRange.location - fullRunRange.location;
CFIndex endActiveLinkInRun = startActiveLinkInRun + (CFIndex)activeLinkRange.length;

CFRange inRunRange;
inRunRange.location = (CFIndex)activeLinkRange.location - (CFIndex)fullRunRange.location;
inRunRange.length = (CFIndex)activeLinkRange.length;
if (inRunRange.location < 0) {
inRunRange.length += inRunRange.location;
inRunRange.location = 0;
}
// End Fix #136
inRunRange.location = MAX(startActiveLinkInRun, 0);
inRunRange.length = MIN(endActiveLinkInRun, fullRunRange.length);

CGRect linkRunRect = CTRunGetTypographicBoundsForRangeAsRect(run, line, lineOrigins[lineIndex], inRunRange, ctx);

linkRunRect = CGRectIntegral(linkRunRect); // putting the rect on pixel edges
Expand Down

0 comments on commit 5d65bee

Please sign in to comment.