Browse Source

Fix text selection
Fix empty line RTL inital caret position

Benedikt Stebner 3 years ago
parent
commit
69f9e017f3

+ 3 - 3
src/Avalonia.Base/Media/TextFormatting/TextFormatterImpl.cs

@@ -528,7 +528,7 @@ namespace Avalonia.Media.TextFormatting
         /// Creates an empty text line.
         /// </summary>
         /// <returns>The empty text line.</returns>
-        public static TextLineImpl CreateEmptyTextLine(int firstTextSourceIndex, TextParagraphProperties paragraphProperties)
+        public static TextLineImpl CreateEmptyTextLine(int firstTextSourceIndex, double paragraphWidth, TextParagraphProperties paragraphProperties)
         {
             var flowDirection = paragraphProperties.FlowDirection;
             var properties = paragraphProperties.DefaultTextRunProperties;
@@ -542,7 +542,7 @@ namespace Avalonia.Media.TextFormatting
 
             var textRuns = new List<DrawableTextRun> { new ShapedTextCharacters(shapedBuffer, properties) };
 
-            return new TextLineImpl(textRuns, firstTextSourceIndex, 0, double.PositiveInfinity, paragraphProperties, flowDirection).FinalizeLine();
+            return new TextLineImpl(textRuns, firstTextSourceIndex, 0, paragraphWidth, paragraphProperties, flowDirection).FinalizeLine();
         }
 
         /// <summary>
@@ -561,7 +561,7 @@ namespace Avalonia.Media.TextFormatting
         {
             if(textRuns.Count == 0)
             {
-                return CreateEmptyTextLine(firstTextSourceIndex, paragraphProperties);
+                return CreateEmptyTextLine(firstTextSourceIndex,paragraphWidth, paragraphProperties);
             }
 
             if (!TryMeasureLength(textRuns, paragraphWidth, out var measuredLength))

+ 3 - 3
src/Avalonia.Base/Media/TextFormatting/TextLayout.cs

@@ -410,7 +410,7 @@ namespace Avalonia.Media.TextFormatting
         {
             if (MathUtilities.IsZero(MaxWidth) || MathUtilities.IsZero(MaxHeight))
             {
-                var textLine = TextFormatterImpl.CreateEmptyTextLine(0, _paragraphProperties);
+                var textLine = TextFormatterImpl.CreateEmptyTextLine(0, double.PositiveInfinity, _paragraphProperties);
 
                 Bounds = new Rect(0,0,0, textLine.Height);
 
@@ -434,7 +434,7 @@ namespace Avalonia.Media.TextFormatting
                 {
                     if(previousLine != null && previousLine.NewLineLength  > 0)
                     {
-                        var emptyTextLine = TextFormatterImpl.CreateEmptyTextLine(_textSourceLength, _paragraphProperties);
+                        var emptyTextLine = TextFormatterImpl.CreateEmptyTextLine(_textSourceLength, MaxWidth, _paragraphProperties);
 
                         textLines.Add(emptyTextLine);
 
@@ -483,7 +483,7 @@ namespace Avalonia.Media.TextFormatting
             //Make sure the TextLayout always contains at least on empty line
             if(textLines.Count == 0)
             {
-                var textLine = TextFormatterImpl.CreateEmptyTextLine(0, _paragraphProperties);
+                var textLine = TextFormatterImpl.CreateEmptyTextLine(0, MaxWidth, _paragraphProperties);
 
                 textLines.Add(textLine);
 

+ 0 - 5
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@@ -418,11 +418,6 @@ namespace Avalonia.Media.TextFormatting
                     continue;
                 }
 
-                if(currentPosition + currentRun.TextSourceLength <= firstTextSourceCharacterIndex)
-                {
-                    continue;
-                }
-
                 TextRun? nextRun = null;
 
                 if (index + 1 < TextRuns.Count)