Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage
ceil(size.width * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor,
ceil(size.height * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor};

NSRange visibleGlyphRange = [layoutManager glyphRangeForTextContainer:textContainer];

__block auto attachments = TextMeasurement::Attachments{};

[textStorage
Expand All @@ -405,7 +407,14 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage
actualCharacterRange:NULL];
NSRange truncatedRange =
[layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:attachmentGlyphRange.location];
if (truncatedRange.location != NSNotFound && attachmentGlyphRange.location >= truncatedRange.location) {

// Attachment on a line that did not fit (e.g. on the 4th line when the container is limited to 3 lines)
BOOL isOutsideVisibleRange = !NSLocationInRange(attachmentGlyphRange.location, visibleGlyphRange);
// Attachment in the ellipsis range of the last visible line (line truncated with "..." and the attachment falls in that portion)
BOOL isInTruncatedRange = truncatedRange.location != NSNotFound &&
attachmentGlyphRange.location >= truncatedRange.location;

if (isOutsideVisibleRange || isInTruncatedRange) {
attachments.push_back(TextMeasurement::Attachment{.isClipped = true});
} else {
CGSize attachmentSize = attachment.bounds.size;
Expand Down
Loading