Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit bd11ae3

Browse files
author
Yuncong Zhang
committed
Cache ellipsized text.
1 parent 41d7879 commit bd11ae3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Runtime/ui/txt/paragraph.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
176176
bool _needsLayout = true;
177177

178178
string _text;
179+
string _ellipsizedText;
180+
int _ellipsizedLength;
179181

180182
StyledRuns _runs;
181183

@@ -435,7 +437,14 @@ public void layout(ParagraphConstraints constraints) {
435437
int truncateCount = Layout.computeTruncateCount(runXOffset, text, textStart,
436438
textCount, style, this._width - ellipsisWidth, this._tabStops);
437439

438-
text = text.Substring(0, textStart + textCount - truncateCount) + ellipsis;
440+
if(!(this._ellipsizedLength == textStart + textCount - truncateCount &&
441+
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
442+
this._ellipsizedText.EndsWith(ellipsis))) {
443+
this._ellipsizedText =
444+
text.Substring(0, textStart + textCount - truncateCount) + ellipsis;
445+
this._ellipsizedLength = this._ellipsizedText.Length - ellipsis.Length;
446+
}
447+
text = this._ellipsizedText;
439448
textCount = text.Length - textStart;
440449
D.assert(textCount != 0);
441450
if (this._paragraphStyle.maxLines == null) {

0 commit comments

Comments
 (0)