Repository navigation
fix(textblock): Return CRLF for explicit line breaks - #26706
Open
ZainnQureshii wants to merge 1 commit into
Open
ZainnQureshii wants to merge 1 commit into
ZainnQureshii wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Text searches spanning explicit line breaks can fail, and replacing equivalent exported text with different inline structures can leave selection offsets and SelectedText stale.
2 open issues
What changed in this PR
This PR addresses #26417 by exporting explicit LineBreak elements as CRLF from TextBlock, matching WinUI while retaining single-position breaks for layout and selection offsets.
Changes:
- Separates exported text from the flat text used for offset calculations.
- Shares inline text extraction with
RichTextBlockand updates selection and UI Automation exports. - Adds regression coverage for literal line endings, nested breaks, selection, and automation ranges.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/Documents/InlineExtensions.cs |
Adds shared CRLF export and selection extraction helpers. |
src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs |
Exports CRLF while maintaining flat selection offsets. |
src/Uno.UI/UI/Xaml/Controls/RichTextBlock/RichTextBlock.mux.cs |
Reuses the shared selection extraction helper. |
src/Uno.UI/UI/Xaml/Controls/RichTextBlock/RichTextBlock.cs |
Reuses shared plain-text export logic. |
src/Uno.UI/DirectUI/TextRangeAdapter.cs |
Exports TextBlock automation ranges with CRLF breaks. |
src/Uno.UI/DirectUI/TextAdapter.cs |
Uses flat text and lengths for automation offsets. |
src/Uno.UI.UnitTests/Windows_UI_XAML_Controls/TextBlockTests/Given_TextBlock.cs |
Adds CRLF, selection, and automation regression assertions. |
Review effort: Balanced
| PasswordBox passwordBox => new string('•', passwordBox.Password?.Length ?? 0), | ||
| TextBox textBox => textBox.Text ?? string.Empty, | ||
| TextBlock textBlock => textBlock.Text ?? string.Empty, | ||
| TextBlock textBlock => textBlock.TextForSelection ?? string.Empty, |
Comment on lines
+202
to
+203
| _inlineLineBreakCount = inlines.Count(static inline => inline is LineBreak); | ||
| _inlinesText = string.Concat(inlines.Select(InlineExtensions.GetPlainText)); |
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.

GitHub Issue: closes #26417
PR Type:
🐞 Bugfix
What changed? 🚀
For
<TextBlock>Line1<LineBreak/>Line2<LineBreak/><LineBreak/>Line4</TextBlock>, Uno returned"Line1\nLine2\n\nLine4". Code that splits the string on CRLF missed the explicit breaks.TextBlock.Textnow returns"Line1\r\nLine2\r\n\r\nLine4", matching the WinUI output reported in #26417 (src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs:201). Literal line endings in aRunretain their original characters.TextBlock.SelectedText, clipboard copy, and UI AutomationITextRangeProvider.GetTextnow also return CRLF for each explicit break. They previously returned LF. The selection and automation offsets still count each explicit break as one position, so selecting the word after a break still returns the whole word.RichTextBlockuses the same inline walk and continues to include its CRLF paragraph terminators (src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs:1994,src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs:2059,src/Uno.UI/DirectUI/TextRangeAdapter.cs:1031,src/Uno.UI/UI/Xaml/Controls/RichTextBlock/RichTextBlock.mux.cs:587,src/Uno.UI/UI/Xaml/Documents/InlineExtensions.cs:36).UI Automation text search, movement, and endpoint calculations still use the LF offset space. TextBox, PasswordBox, and RichEditBox use their existing text paths. RichEditBox's internal display block uses runs and hyperlinks, so its known-text update path has no explicit
LineBreakto expand (src/Uno.UI/DirectUI/TextAdapter.cs:46,src/Uno.UI/DirectUI/TextRangeAdapter.cs:627,src/Uno.UI/UI/Xaml/Controls/RichEditBox/RichEditBox.rendering.cs:695).Layout and RichTextBlock overflow still read the flat inline text, so a CRLF export cannot shift their offsets (
src/Uno.UI/UI/Xaml/Documents/ParsedText.cs:48,src/Uno.UI/UI/Xaml/Controls/RichTextBlock/RichTextBlockOverflow.mux.cs:436).On macOS arm64 with .NET SDK 11.0.100, the two CRLF assertions failed independently on
3938657de(both exit 2). The final Release unit build had zero warnings and errors. The focused test passed with both assertions, theRange(0, 18)check, and the word range after the break. The related filter passed all 18 tests. The whitespace check reported zero changes across seven files. All final checks below exited 0.The macOS unit test host used the native dylibs from
Uno.icu-macos77.4.1 insrc/Uno.UI.UnitTests/bin/AnyCPU/Release/net11.0/.Both Skia Desktop builds completed with the macOS native host compiled using Apple's Command Line Tools. On this host, the desktop app stalled at startup and produced no test report. A separate scratch probe passed before and after the change for RichTextBlock selection after and across an explicit break, paragraph endings, and a nested inline edit.
PR Checklist ✅
Screenshots Compare Test Runresults.Prepared with AI assistance (Codex and Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code