Skip to content

Fix showing ellipsis when word wrap and limited by height or MaxLines - #22025

Open
appel1 wants to merge 3 commits into
AvaloniaUI:mainfrom
appel1:issue17633
Open

Fix showing ellipsis when word wrap and limited by height or MaxLines#22025
appel1 wants to merge 3 commits into
AvaloniaUI:mainfrom
appel1:issue17633

Conversation

@appel1

@appel1 appel1 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Fixes a bug

What is the current behavior?

Ellipsis is not shown when text is truncated when the TextBlock is limited by height or MaxLines.

What is the updated/expected behavior with this PR?

Ellipsis is shown when text is truncated.

Fixed issues

Fixes #17633

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Aug 20, 2026
@Gillibald

Gillibald commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

A duplicate of #22017

This PR also complicates things a lot for no reason. Pass the last visible line's width as the collapsing width, and it will correctly collapse.

@appel1

appel1 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Oh well, thought I had checked for other PRs, but obviously I failed. If the other one solves the issues we can just drop this one.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068575-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@appel1

appel1 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

With the #22017 PR the following tests I added fails. I don't think it is intended behavior.

1.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis 

Assert.Contains() Failure: Sub-string not found
String:    "second line\r\n"
Not found: "…"
  at TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis() line 879

2.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis_WordEllipsis 

Assert.Contains() Failure: Sub-string not found
String:    "second line\r\n"
Not found: "…"
  at TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis_WordEllipsis() line 912

3.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_Wrap_CharacterEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line 

Assert.Contains() Failure: Sub-string not found
String:    "Lorem ipsum dolor sit amet, "
Not found: "…"
  at TextBlockTests.TextBlock_With_Wrap_CharacterEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line() line 694

4.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_Wrap_WordEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line 

Assert.Contains() Failure: Sub-string not found
String:    "Lorem ipsum dolor sit amet, "
Not found: "…"
  at TextBlockTests.TextBlock_With_Wrap_WordEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line() line 764

5.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_MaxHeight_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis 

Assert.Contains() Failure: Sub-string not found
String:    "second line\r\n"
Not found: "…"
  at TextBlockTests.TextBlock_With_MaxHeight_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis() line 948

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068581-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@puk06

puk06 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

With the #22017 PR the following tests I added fails. I don't think it is intended behavior.

1.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis 

Assert.Contains() Failure: Sub-string not found
String:    "second line\r\n"
Not found: "…"
  at TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis() line 879

2.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis_WordEllipsis 

Assert.Contains() Failure: Sub-string not found
String:    "second line\r\n"
Not found: "…"
  at TextBlockTests.TextBlock_With_MaxLines_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis_WordEllipsis() line 912

3.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_Wrap_CharacterEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line 

Assert.Contains() Failure: Sub-string not found
String:    "Lorem ipsum dolor sit amet, "
Not found: "…"
  at TextBlockTests.TextBlock_With_Wrap_CharacterEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line() line 694

4.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_Wrap_WordEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line 

Assert.Contains() Failure: Sub-string not found
String:    "Lorem ipsum dolor sit amet, "
Not found: "…"
  at TextBlockTests.TextBlock_With_Wrap_WordEllipsis_And_Height_Limit_Should_Show_Ellipsis_On_Last_Line() line 764

5.  Avalonia.Controls.UnitTests.TextBlockTests.TextBlock_With_MaxHeight_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis 

Assert.Contains() Failure: Sub-string not found
String:    "second line\r\n"
Not found: "…"
  at TextBlockTests.TextBlock_With_MaxHeight_And_Hidden_Content_After_NewLine_Should_Show_Ellipsis() line 948

The changes in my pull request only address issues with the previous implementation; the handling of manual line breaks (\r\n) remains unchanged. As before, ellipses are displayed only when a string is wrapped (IsSplit = true).

Since IsSplit is set to true only when a line break occurs via WrappingTextLineBreak, it should be set to false for manual line breaks, meaning the ellipsis should not be displayed. I apologize if I’m mistaken.

@appel1

appel1 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I updated the PR so that a height limit clips silently (no   ) when the last visible line ends at a hard paragraph break — matching WPF and CSS max-height + overflow:hidden.

Scenario #22017 This PR
Wrapped text cut by MaxLines
Wrapped text cut by MaxHeight
Double …… prevention
Hard breaks hidden by MaxLines — shows

A question here is if MaxLines + TextTrimming should show    when content is hidden only due to the line count limit (last visible line fits the width)? CSS line-clamp does. WPF doesn't have this feature.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068613-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Gillibald Gillibald self-assigned this Aug 24, 2026
@appel1

appel1 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (which now includes merged #22017). Note that #22017 only fixed the MaxLines collapsing width (using the layout-wide width instead of the specific line's width); this PR fixes that plus the equivalent MaxHeight case, adds a wrap-split vs. hard-paragraph-break distinction (matching WPF/HTML overflow:hidden clip behavior when the last visible line isn't itself trimmed), guards against double-ellipsis when text already overflowed, and covers RTL wrapped MaxLines.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068968-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextBlock TextTrimming=CharacterEllipsis, TextWrapping=Wrap, MaxLines="2" does not always show ellipsis

5 participants