Skip to content

Commit 46ad23f

Browse files
committed
fix: iOS - wrap mentions tightly, don't highlight entire line height
1 parent f1b8c74 commit 46ad23f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apple/MarkdownTextLayoutFragment.mm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,20 @@ - (void)drawMentions {
8282
CGFloat width = endLocation.x - startLocation.x;
8383
CGFloat x = lineBounds.origin.x + startLocation.x;
8484

85+
NSUInteger lineRelativeLocation = intersection.location - lineFragment.characterRange.location;
86+
UIFont *font = [lineFragment.attributedString attribute:NSFontAttributeName
87+
atIndex:lineRelativeLocation
88+
effectiveRange:NULL];
89+
CGFloat ascent = font.ascender;
90+
CGFloat descent = font.descender;
91+
CGFloat textHeight = ascent - descent;
92+
CGFloat y = (startLocation.y - ascent) / 2;
93+
94+
8595
CGRect backgroundRect = CGRectMake(x,
86-
lineBounds.origin.y,
96+
y,
8797
width,
88-
lineBounds.size.height);
98+
textHeight);
8999

90100
BOOL isStart = (intersection.location == mention.range.location);
91101
BOOL isEnd = (NSMaxRange(intersection) == NSMaxRange(mention.range));

0 commit comments

Comments
 (0)