Skip to content

TextBlock.Text reports a LineBreak as "\n" instead of "\r\n" like WinUI #26417

Open

Description

@MartinZikmund

Current behavior 🐛

Severity: Low - code that compares or splits TextBlock.Text sees a different string than on WinUI (\n instead of \r\n); nothing crashes and nothing renders wrong.

When a TextBlock is built from inlines, Text reports each <LineBreak/> as "\n":

<TextBlock>Line1<LineBreak/>Line2<LineBreak/><LineBreak/>Line4</TextBlock>

Text is "Line1\nLine2\n\nLine4" on Uno.

Expected behavior 🎯

On WinUI, Text is "Line1\r\nLine2\r\n\r\nLine4". Each LineBreak reads back as "\r\n".

How to reproduce it (as minimally and precisely as possible) 🔬

  1. Create an app with a page containing the XAML above, named tb.
  2. After it loads, read tb.Text and print it with \r/\n escaped (e.g. tb.Text.Replace("\r", "\r").Replace("\n", "\n")).
  3. Uno Skia desktop prints Line1\nLine2\n\nLine4. WinUI 3 prints Line1\r\nLine2\r\n\r\nLine4.

A Text that contains a literal LF reads back unchanged on both, so only the inline-built path differs.

Workaround 🛠️

Normalize line endings when reading Text, e.g. tb.Text.Replace("\r\n", "\n").

Works on UWP/WinUI

Yes (\r\n).

Affected platforms 📱💻🖥️

Skia Desktop (Win32). The shared code is not platform-specific, so other Skia heads are likely affected too (not tested).

Uno.Sdk version (and other relevant versions) 📦

Uno master 4636b705e97 (2026-11-12), net11.0-desktop, .NET SDK 11.0.100. InlineExtensions.cs has not changed on master since (git log 4636b705e97..origin/master is empty for it).

Anything else we need to know? 💬

What was verified

  • Runtime on Uno: a prebuilt Release SamplesApp of 4636b705e97, Skia desktop, re-run on 2026-11-13. It printed "Line1\nLine2\n\nLine4".
  • Runtime on WinUI: the same probe on a WinUI 3 app (WinAppSDK 2.5.1) printed "Line1\r\nLine2\r\n\r\nLine4".

Root cause
InlineExtensions.GetText returns "\n" for a LineBreak. TextBlock uses it to build _inlinesText and then Text.

Careful with the fix
GetText is also the flat character index space for layout: ParsedText assumes a LineBreak is exactly one character, and ParagraphTextSource, UnicodeText, MathTextLayout and the RichTextBlock offset code also use its lengths. Changing it to "\r\n" would shift every offset after a LineBreak by one (selection, hit testing, text pointers). A safer fix is probably what RichTextBlock already does in GetPlainTextOf: keep GetText for layout and build the public Text with "\r\n" separately.

Related but different bug: #26148 (CR and LF in different inlines make one line break instead of two).

Activity

  1. added
    kind/bug
    triage/untriaged
    area/skia ✏️
    area/textblock
    project/text 🔤
    difficulty/medium 🤔
    on Nov 13, 2026
  2. ZainnQureshii commented on Nov 23, 2026

    @ZainnQureshii

    Hi, could you assign this one to me? I reproduced it in Uno's unit tests on macOS and I have a fix ready that returns CRLF for an explicit LineBreak, with a regression test that also checks the selection after the break.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/skia ✏️area/textblockdifficulty/medium 🤔kind/bugproject/text 🔤triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions