Skip to content

fix(SelectableTextBlock): fix SelectableTextBlock selection for centered and right-aligned text#21369

Open
zrt2399 wants to merge 2 commits into
AvaloniaUI:masterfrom
zrt2399:fix_issue_21368
Open

fix(SelectableTextBlock): fix SelectableTextBlock selection for centered and right-aligned text#21369
zrt2399 wants to merge 2 commits into
AvaloniaUI:masterfrom
zrt2399:fix_issue_21368

Conversation

@zrt2399
Copy link
Copy Markdown
Contributor

@zrt2399 zrt2399 commented May 15, 2026

fix #21368

What does the pull request do?

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

SelectableTextBlock was unable to select the full text content when TextAlignment was set to Center or Right.
The issue was caused by pointer hit-testing during drag selection clamping the X coordinate to TextLayout.WidthIncludingTrailingWhitespace. For centered and right-aligned text, the rendered text can start later within the available layout width, so clamping to the text width prevented the selection logic from reaching the trailing characters.
This change updates the drag-selection hit-testing logic to clamp against the available layout width when appropriate, allowing selection to extend to the visual end of the text for non-left-aligned content.
Also added regression tests covering drag selection with Center and Right text alignment, and normalized the sample XAML self-closing tag formatting to keep build validation clean.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

fix #21368

@avaloniaui-bot
Copy link
Copy Markdown

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

@MrJul MrJul added bug backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels May 18, 2026
@MrJul MrJul requested a review from Gillibald May 18, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectableTextBlock cannot select all text when TextAlignment is Center or Right

3 participants