Skip to content

Commit

Permalink
Don't add extraneous truncation token during kCTLineTruncationMiddle. (
Browse files Browse the repository at this point in the history
…#1297)

* Don't add extraneous truncation token during kCTLineTruncationMiddle

* Expand these comments a little.
  • Loading branch information
wiseoldduck authored and Adlai-Holler committed Mar 6, 2019
1 parent a0012d9 commit 7bb3079
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/Private/TextExperiment/Component/ASTextLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,8 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri
}
}
int i = 0;
if (type != kCTLineTruncationStart) { // Middle or End/Tail wants text preceding truncated content.
if (type != kCTLineTruncationStart) { // Middle or End/Tail wants to collect some text (at least one line's
// worth) preceding the truncated content, with which to construct a "truncated line".
i = (int)removedLines.count - 1;
while (atLeastOneLine < truncatedWidth && i >= 0) {
if (lastLineText.length > 0 && [lastLineText.string characterAtIndex:lastLineText.string.length - 1] == '\n') { // Explicit newlines are always "long enough".
Expand All @@ -846,7 +847,8 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri
}
[lastLineText appendAttributedString:truncationToken];
}
if (type != kCTLineTruncationEnd && removedLines.count > 0) { // Middle or Start/Head wants text following truncated content.
if (type != kCTLineTruncationEnd && removedLines.count > 0) { // Middle or Start/Head wants to collect some
// text following the truncated content.
i = 0;
atLeastOneLine = removedLines[i].width;
while (atLeastOneLine < truncatedWidth && i < removedLines.count) {
Expand All @@ -860,7 +862,9 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri
[lastLineText appendAttributedString:nextLine];
}
}
[lastLineText insertAttributedString:truncationToken atIndex:0];
if (type == kCTLineTruncationStart) {
[lastLineText insertAttributedString:truncationToken atIndex:0];
}
}

CTLineRef ctLastLineExtend = CTLineCreateWithAttributedString((CFAttributedStringRef) lastLineText);
Expand Down

0 comments on commit 7bb3079

Please sign in to comment.