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

Commit 4e42591

Browse files
author
Yuncong Zhang
committed
Optimize getNextLineStartRect.
1 parent 0b560a6 commit 4e42591

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

Runtime/painting/text_painter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ public Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) {
212212
var prevCodeUnit = this._text.codeUnitAt(offset);
213213
if (prevCodeUnit == null) // out of upper bounds
214214
{
215-
var rectNextLine = this._paragraph.getNextLineStartRect();
216-
if (rectNextLine != null) {
217-
return new Offset(((TextBox) rectNextLine).start, ((TextBox) rectNextLine).top);
215+
var rectNextLineTop = this._paragraph.getNextLineStartRectTop();
216+
if (rectNextLineTop != null) {
217+
return new Offset(0, (float) rectNextLineTop);
218218
}
219219
}
220220
}

Runtime/ui/txt/paragraph.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,15 +726,13 @@ public List<TextBox> getRectsForRange(int start, int end) {
726726
return result;
727727
}
728728

729-
public TextBox? getNextLineStartRect() {
729+
public float? getNextLineStartRectTop() {
730730
if (this._text.Length == 0 || this._text[this._text.Length - 1] != '\n') {
731731
return null;
732732
}
733733

734734
var lineNumber = this.getLineCount() - 1;
735-
var top = (lineNumber > 0) ? this._lineHeights[lineNumber - 1] : 0;
736-
var bottom = this._lineHeights[lineNumber];
737-
return TextBox.fromLTBD(0, top, 0, bottom, TextDirection.ltr);
735+
return lineNumber > 0 ? this._lineHeights[lineNumber - 1] : 0;
738736
}
739737

740738
internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {

0 commit comments

Comments
 (0)