Skip to content

Commit db30e60

Browse files
RBridCopilot
andauthored
Fix bullet/list text clipping in chat (issue #636) (#637)
Markdown list rows used HStack (horizontal StackPanel), which measures children with infinite width. The paragraph TextBlock therefore never wrapped and long bullets got clipped by the chat bubble's max width. Switch each list row to a 2-column Grid (Auto marker + Star content) so the content column receives a finite width and TextWrapping=Wrap works as intended. Co-authored-by: Copilot <[email protected]>
1 parent f4d4793 commit db30e60

2 files changed

Lines changed: 119 additions & 5 deletions

File tree

‎src/OpenClaw.Tray.WinUI/Chat/Markdown/ChatMarkdownRenderer.cs‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ private static Element RenderRaw(MdRawTextBlock raw) =>
288288

289289
private const double BulletMarkerMinWidth = 10.0;
290290
private const double OrderedMarkerMinWidth = 18.0;
291-
private const double ListMarkerSpacing = 0.0;
292291

293292
private static Element RenderList(MdList list)
294293
{
294+
// Allocated per list (not per row) and not shared across calls, so the
295+
// arrays can't be mutated by anyone else between renders.
296+
var columns = new[] { GridSize.Auto, GridSize.Star() };
297+
var rowDefs = new[] { GridSize.Auto };
298+
295299
var rows = new List<Element?>(list.Items.Count);
296300
int number = list.Marker == MdListMarker.Ordered ? list.StartNumber : 0;
297301
bool isOrdered = list.Marker == MdListMarker.Ordered;
@@ -306,13 +310,20 @@ private static Element RenderList(MdList list)
306310
};
307311
if (isOrdered) number++;
308312

309-
rows.Add(HStack(
310-
ListMarkerSpacing,
313+
// A Grid is used here (rather than a horizontal StackPanel) so the
314+
// content column receives a finite width during measure and the
315+
// paragraph TextBlock can wrap. Inside a horizontal StackPanel the
316+
// content would be measured with infinite width and long bullets
317+
// would render on a single clipped line. See issue #636.
318+
rows.Add(Grid(
319+
columns,
320+
rowDefs,
311321
TextBlock(marker)
312322
.FontSize(BodyFontSize)
313323
.VAlign(VerticalAlignment.Top)
314-
.MinWidth(markerMinWidth),
315-
RenderListItemContent(item)));
324+
.MinWidth(markerMinWidth)
325+
.Grid(row: 0, column: 0),
326+
RenderListItemContent(item).Grid(row: 0, column: 1)));
316327
}
317328
return VStack(4.0, rows.ToArray());
318329
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using OpenClawTray.Chat.Markdown;
2+
using OpenClawTray.FunctionalUI;
3+
using OpenClawTray.FunctionalUI.Core;
4+
using Xunit;
5+
6+
namespace OpenClaw.Tray.UITests;
7+
8+
/// <summary>
9+
/// Regression tests for GitHub issue #636 ("Text is sometimes clipped in Chat").
10+
///
11+
/// The bug: list rows used to be built as a horizontal <see cref="StackElement"/>
12+
/// (<c>HStack(marker, content)</c>), which materializes to a horizontal
13+
/// <see cref="Microsoft.UI.Xaml.Controls.StackPanel"/>. A horizontal StackPanel
14+
/// measures children with infinite available width, so the paragraph's
15+
/// <see cref="Microsoft.UI.Xaml.Controls.TextBlock"/> (with
16+
/// <c>TextWrapping = Wrap</c>) never wraps — long bullets render on a single
17+
/// line and get clipped by the chat bubble's max width.
18+
///
19+
/// The fix: each row is now a 2-column <see cref="GridElement"/>
20+
/// (<c>Auto</c> marker + <c>*</c> content). The Star column gives the content
21+
/// a finite measure width, so wrap works correctly.
22+
///
23+
/// These assertions live at the FunctionalUI <see cref="Element"/> record level
24+
/// (no WinUI runtime needed) because that's where the regression would surface:
25+
/// any change of the row container back to a horizontal stack would fail these
26+
/// tests immediately.
27+
/// </summary>
28+
public sealed class MarkdownRendererListTests
29+
{
30+
[Fact]
31+
public void UnorderedListRow_IsGridWithAutoMarkerAndStarContent()
32+
{
33+
const string longBullet =
34+
"- This is an unusually long bullet that must wrap across multiple " +
35+
"lines instead of being clipped at the right edge of the chat bubble.";
36+
37+
var element = ChatMarkdownRenderer.Render(longBullet);
38+
39+
var list = Assert.IsType<StackElement>(element);
40+
Assert.Equal(Microsoft.UI.Xaml.Controls.Orientation.Vertical, list.Orientation);
41+
Assert.Single(list.Children);
42+
43+
var row = Assert.IsType<GridElement>(list.Children[0]!);
44+
AssertListRowShape(row);
45+
}
46+
47+
[Fact]
48+
public void OrderedListRows_EachUseGridWithAutoMarkerAndStarContent()
49+
{
50+
const string ordered = "1. first item\n2. second item\n3. third item";
51+
52+
var element = ChatMarkdownRenderer.Render(ordered);
53+
54+
var list = Assert.IsType<StackElement>(element);
55+
Assert.Equal(Microsoft.UI.Xaml.Controls.Orientation.Vertical, list.Orientation);
56+
Assert.Equal(3, list.Children.Count);
57+
58+
foreach (var child in list.Children)
59+
{
60+
var row = Assert.IsType<GridElement>(child!);
61+
AssertListRowShape(row);
62+
}
63+
}
64+
65+
[Fact]
66+
public void ListRow_IsNotAHorizontalStackPanel()
67+
{
68+
// Direct guard against the original regression: if anyone reverts the
69+
// row container to HStack(...), this fails with a clear message.
70+
const string bullet = "- something";
71+
72+
var element = ChatMarkdownRenderer.Render(bullet);
73+
74+
var list = Assert.IsType<StackElement>(element);
75+
var row = list.Children[0];
76+
if (row is StackElement stackRow)
77+
Assert.Fail(
78+
$"List row regressed to a {stackRow.Orientation} StackElement. " +
79+
"Issue #636 requires a GridElement so the content column gets " +
80+
"a finite measure width and TextBlock wrap works.");
81+
}
82+
83+
private static void AssertListRowShape(GridElement row)
84+
{
85+
// Auto column for the marker, Star column for the wrapping content.
86+
Assert.Equal(new[] { "Auto", "*" }, row.Columns);
87+
Assert.Equal(new[] { "Auto" }, row.Rows);
88+
Assert.Equal(2, row.Children.Count);
89+
90+
var marker = row.Children[0];
91+
var content = row.Children[1];
92+
Assert.NotNull(marker);
93+
Assert.NotNull(content);
94+
95+
Assert.NotNull(marker!.GridPosition);
96+
Assert.Equal(0, marker.GridPosition!.Row);
97+
Assert.Equal(0, marker.GridPosition.Column);
98+
99+
Assert.NotNull(content!.GridPosition);
100+
Assert.Equal(0, content.GridPosition!.Row);
101+
Assert.Equal(1, content.GridPosition.Column);
102+
}
103+
}

0 commit comments

Comments
 (0)