Skip to content

Commit dcc9f6f

Browse files
committed
Merge pull request #162 from mattjgalloway/FixHighlightMultipleLines
Fix where the highlight is made if it spans multiple lines
2 parents a658a99 + 5d65bee commit dcc9f6f

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

OHAttributedLabel/Source/OHAttributedLabel.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,15 @@ -(void)drawActiveLinkHighlightForRect:(CGRect)rect
666666
continue; // with next run
667667
}
668668

669-
// Fix for issue #136
670669
CFRange fullRunRange = CTRunGetStringRange(run);
670+
671+
CFIndex startActiveLinkInRun = (CFIndex)activeLinkRange.location - fullRunRange.location;
672+
CFIndex endActiveLinkInRun = startActiveLinkInRun + (CFIndex)activeLinkRange.length;
673+
671674
CFRange inRunRange;
672-
inRunRange.location = (CFIndex)activeLinkRange.location - (CFIndex)fullRunRange.location;
673-
inRunRange.length = (CFIndex)activeLinkRange.length;
674-
if (inRunRange.location < 0) {
675-
inRunRange.length += inRunRange.location;
676-
inRunRange.location = 0;
677-
}
678-
// End Fix #136
675+
inRunRange.location = MAX(startActiveLinkInRun, 0);
676+
inRunRange.length = MIN(endActiveLinkInRun, fullRunRange.length);
677+
679678
CGRect linkRunRect = CTRunGetTypographicBoundsForRangeAsRect(run, line, lineOrigins[lineIndex], inRunRange, ctx);
680679

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

0 commit comments

Comments
 (0)