Skip to content

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

Merged
MrJul merged 5 commits into
AvaloniaUI:mainfrom
zrt2399:fix_issue_21368
Aug 7, 2026
Merged

MrJul merged 5 commits into
AvaloniaUI:mainfrom
zrt2399:fix_issue_21368

Conversation

@zrt2399

@zrt2399 zrt2399 commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

What does the pull request do?

Fix SelectableTextBlock selection for centered and right-aligned text

What is the current behavior?

SelectableTextBlock cannot select all text when text is centered or right-aligned.

What is the updated/expected behavior with this PR?

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

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.

Checklist

Fixed issues

Fixes #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
Comment thread src/Avalonia.Controls/SelectableTextBlock.cs Outdated
@avaloniaui-bot

Copy link
Copy Markdown

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

@avaloniaui-bot

Copy link
Copy Markdown

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

@zrt2399

zrt2399 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated. I removed the clamping and now pass the layout-relative pointer position directly to TextLayout.HitTestPoint.

@MrJul MrJul added backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 9, 2026
@MrJul
MrJul requested a review from Gillibald July 28, 2026 12:08
# Conflicts:
#	src/Avalonia.Controls/SelectableTextBlock.cs
#	tests/Avalonia.Controls.UnitTests/SelectableTextBlockTests.cs
MrJul
MrJul previously approved these changes Aug 7, 2026

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MrJul
MrJul dismissed Gillibald’s stale review August 7, 2026 14:59

The requested changes have been made.

@MrJul
MrJul enabled auto-merge August 7, 2026 14:59
@MrJul
MrJul added this pull request to the merge queue Aug 7, 2026
@avaloniaui-bot

Copy link
Copy Markdown

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

Merged via the queue into AvaloniaUI:main with commit faf7137 Aug 7, 2026
10 checks passed
MrJul added a commit to MrJul/Avalonia that referenced this pull request Sep 2, 2026
…red and right-aligned text (AvaloniaUI#21369)

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

* Fix failing unit tests

* Let TextLayout handle out-of-bounds hit testing

---------

Co-authored-by: Julien Lebosquain 
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectableTextBlock cannot select all text when TextAlignment is Center or Right

4 participants