Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichEditBox in UWP/WinUI3 Loses Font Family Settings for Subsequent Lines if the First Line Contains Only a Newline #9757

Open
KennethVScom opened this issue Jun 25, 2024 · 4 comments
Labels
area-TextBox TextBox, RichEditBox bug Something isn't working team-Controls Issue for the Controls team

Comments

@KennethVScom
Copy link

Describe the bug

When using the RichEditBox control in UWP or WinUI3, if the content's first line consists solely of a newline character, the font family settings for subsequent lines are lost after calling the RichEditBox.Document.GetText() method. This results in the text reverting to the default system font family (Segoe UI), rather than retaining the user-defined font family settings.

Steps to reproduce the bug

  1. Create a UWP or WinUI3 application with a RichEditBox control.
  2. Set the initial content of the RichEditBox such that the first line is a newline character.
  3. Add text to subsequent lines with a specific font family setting.
  4. Use the RichEditBox.Document.GetText() method to retrieve the content of the RichEditBox.
  5. Observe that the font family settings for the text after the first newline character revert to the default system font family.

Expected behavior

The font family settings for all lines, including those following the first newline character, should be preserved after calling the RichEditBox.Document.GetText() method.

Screenshots

image

NuGet package version

None

Windows version

Windows 11 (22H2): Build 22621, Windows 10 (21H2): Build 19044

Additional context

No response

@KennethVScom KennethVScom added the bug Something isn't working label Jun 25, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jun 25, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@codendone codendone added area-TextBox TextBox, RichEditBox team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jul 2, 2024
@kmahone
Copy link
Member

kmahone commented Jul 19, 2024

@KennethVScom I tried to repro this issue follow the steps in the description but did not reproduce the bug. Would you be able to share a WinUI3 sample app that demonstrates the problem?

In the scenario where you are seeing this bug, just calling RichEditBox.Document.GetText() causes the text formatting to disappear - is that correct?

@kmahone kmahone added the needs-author-feedback Asked author to supply more information. label Jul 23, 2024
@KennethVScom
Copy link
Author

KennethVScom commented Jul 31, 2024

@KennethVScom I tried to repro this issue follow the steps in the description but did not reproduce the bug. Would you be able to share a WinUI3 sample app that demonstrates the problem?

@kmahone Sorry for the late reply.
Please refer to the sample project here, just click the Add Simple button and then click the Copy and Paste button to reproduce the issue.

In the scenario where you are seeing this bug, just calling RichEditBox.Document.GetText() causes the text formatting to disappear - is that correct?

Yes, that is correct!

Thank you.

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. no-recent-activity labels Jul 31, 2024
@JesseCol JesseCol removed the needs-triage Issue needs to be triaged by the area owners label Aug 1, 2024
@iomismo
Copy link

iomismo commented Sep 10, 2024

I have similar problems. Selecting last char of the last line also reverts font family to default one:

image

Also, if in a new document you type something and then undo it (leaving the text empty), it also reverts to default font properties:

image

There is a RichEditTextDocument.IgnoreTrailingCharacterSpacing property, but it has no impact whatever it is true or false (if this has something to do with the problem). Its description:
Gets or sets a value that indicates whether character spacing is applied to the last character in a line.
true if spacing is applied to the last character in a line of text; otherwise, false. The default is false.

Default is false, but the last char is applied. And as mentioned, there is no change if it is set to true or false.
It's also a bit ambiguous. If the property is called IgnoreTrailing, perhaps the true value should be don't add the last character.

Directly using Document.GetText also adds an extra rtf line to the end of the text. But if you set the range of the selection to the entire text and call GetText from that Selection, it gets the text correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TextBox TextBox, RichEditBox bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

5 participants