Skip to content

Commit cbdfc9e

Browse files
authored
Updated FormattedStringExtensions.cs (dotnet#25892)
1 parent ce52028 commit cbdfc9e

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/Controls/src/Core/Platform/Android/Extensions/FormattedStringExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ public static void RecalculateSpanPositions(this TextView textView, Label elemen
204204
var spanStartX = (int)layout.GetPrimaryHorizontal(startOffset);
205205

206206
var endOffset = (curLine == spanEndLine) ? spanEndOffset : lineVisibleEndOffset;
207-
var spanEndX = (int)layout.GetSecondaryHorizontal(endOffset);
207+
var validEndOffset = System.Math.Min(endOffset, layout.GetLineEnd(curLine));
208+
var spanEndX = (int)layout.GetSecondaryHorizontal(validEndOffset);
208209

209210
var spanWidth = spanEndX - spanStartX;
210211
var spanLeftX = spanStartX;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.ComponentModel;
2+
using Microsoft.Maui.Controls.PlatformConfiguration;
3+
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
4+
using Entry = Microsoft.Maui.Controls.Entry;
5+
6+
namespace Maui.Controls.Sample.Issues
7+
{
8+
9+
[Issue(IssueTracker.Github, 25836, "Span with tail truncation and paragraph breaks with exception", PlatformAffected.Android)]
10+
public class Issue25836 : ContentPage
11+
{
12+
public Issue25836()
13+
{
14+
var span = new Span
15+
{
16+
Text =
17+
" Mi augue molestie ligula lobortis enim Velit, in. \n Imperdiet eu dignissim odio. Massa erat Hac inceptos facilisis nibh " +
18+
" Interdum massa Consectetuer risus sociis molestie facilisi enim. Class gravida. \n Gravida sociosqu cras Quam velit, suspendisse" +
19+
" leo auctor odio integer primis dui potenti dolor faucibus augue justo morbi ornare sem. "
20+
};
21+
22+
var formattedString = new FormattedString();
23+
formattedString.Spans.Add(span);
24+
25+
var label = new Label
26+
{
27+
AutomationId = "Label",
28+
LineBreakMode = LineBreakMode.TailTruncation,
29+
VerticalOptions = LayoutOptions.Start,
30+
FormattedText = formattedString,
31+
MaxLines = 3
32+
};
33+
34+
var layout = new StackLayout();
35+
layout.Children.Add(label);
36+
37+
Content = layout;
38+
}
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue25836 : _IssuesUITest
8+
{
9+
public Issue25836(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "Span with tail truncation and paragraph breaks with exception";
14+
15+
[Test]
16+
[Category(UITestCategories.Label)]
17+
public void ExceptionShouldNotBeThrown()
18+
{
19+
App.WaitForElement("Label");
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)