Skip to content

Commit

Permalink
Merge pull request #6053 from AvaloniaUI/fixes/6051-multiline-textbox…
Browse files Browse the repository at this point in the history
…-caret-pos

Fix caret positioning with empty newlines.
  • Loading branch information
Dan Walmsley committed Jun 11, 2021
2 parents 93f921c + 14ea7b4 commit 1ea16bf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Skia/Avalonia.Skia/FormattedTextImpl.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Avalonia.Media;
using Avalonia.Platform;
Expand Down Expand Up @@ -175,7 +176,8 @@ public IEnumerable<Rect> HitTestTextRange(int index, int length)

foreach (var line in _skiaLines.Where(l =>
(l.Start + l.Length) > index &&
lastIndex >= l.Start))
lastIndex >= l.Start &&
!l.IsEmptyTrailingLine))
{
int lineEndIndex = line.Start + (line.Length > 0 ? line.Length - 1 : 0);

Expand Down Expand Up @@ -466,7 +468,8 @@ private void BuildRects()

for (int i = line.Start; i < line.Start + line.TextLength; i++)
{
float w = _paint.MeasureText(Text[i].ToString());
var c = Text[i];
var w = line.IsEmptyTrailingLine ? 0 :_paint.MeasureText(Text[i].ToString());

_rects.Add(new Rect(
prevRight,
Expand Down Expand Up @@ -611,6 +614,7 @@ private void Rebuild()
lastLine.Width = lastLineWidth;
lastLine.Height = _lineHeight;
lastLine.Top = curY;
lastLine.IsEmptyTrailingLine = true;

_skiaLines.Add(lastLine);

Expand Down Expand Up @@ -713,6 +717,7 @@ private struct AvaloniaFormattedTextLine
public int TextLength;
public float Top;
public float Width;
public bool IsEmptyTrailingLine;
};

private struct FBrushRange
Expand Down

0 comments on commit 1ea16bf

Please sign in to comment.