Repository navigation
Conversation
…oniaUI#15880) EmbeddedControlRun inherits TextRun.DefaultTextSourceLength = 1, so each InlineUIContainer occupies one position in TextLayout. However, InlineUIContainer.AppendText was a no-op, causing Inlines.Text to have zero characters for each embedded control. This made TextLayout.HitTestPoint return positions that were ahead of Inlines.Text indices by one per InlineUIContainer, breaking SelectedText for any text after an embedded control. Fix: append the Unicode Object Replacement Character (U+FFFC) — the standard placeholder for embedded objects — in AppendText so that Inlines.Text character offsets stay in sync with the TextLayout positions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace single assertion with a [Theory] covering all boundary positions around the embedded control in 'foo\uFFFCbar': - entirely before the container - exactly the container character - up to and including the container - starting exactly after the container - container through end - one character either side of the container - entire content Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
JoshuaRowePhantom
marked this pull request as ready for review
June 24, 2026 21:44
|
You can test this PR using the following package version. |
Collaborator
|
Contributor
Author
|
@cla-avalonia agree |
Gillibald
approved these changes
Jul 6, 2026
Gillibald
left a comment
Contributor
There was a problem hiding this comment.
RichTextEditor(FlowDocument) does the same
LGTM
MrJul
added this pull request to the merge queue
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15880
Problem
EmbeddedControlRun (created by InlineUIContainer.BuildTextRun) inherits TextRun.DefaultTextSourceLength = 1, so each embedded control occupies one position in the TextLayout. However, InlineUIContainer.AppendText was a no-op, meaning Inlines.Text had zero characters for each embedded control.
This caused TextLayout.HitTestPoint to return positions that were ahead of Inlines.Text indices by one for every InlineUIContainer before the cursor, breaking SelectedText for any text after an embedded control.
Fix
Append the Unicode Object Replacement Character (U+FFFC) in InlineUIContainer.AppendText — the standard placeholder for embedded objects (used by WPF for the same purpose) — so that Inlines.Text character offsets stay in sync with TextLayout positions.
Testing
Added a unit test to SelectableTextBlockTests that verifies SelectedText returns the correct value when the selection range spans text after an InlineUIContainer.