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

Significant inline space being removed on Save from Content element #510

Open
michael-hawker opened this issue Sep 11, 2024 · 2 comments
Open

Comments

@michael-hawker
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

<Paragraph>
    This example shows how to add a host object to the WebView. See <Hyperlink
        FontWeight="SemiBold"
        NavigateUri="https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.addhostobjecttoscript"
        UnderlineStyle="None">
        here
    </Hyperlink>
    for more details about the AddHostObjectToScript API.</Paragraph>
<Paragraph />

image

With XAML Styler:

image

<Paragraph>
    This example shows how to add a host object to the WebView. See<Hyperlink

On Save now with XAML Styler enabled, the significant space after See providing separation from the Hyperlink inline element is removed!

To Reproduce
Steps to reproduce the behavior:

  1. When formatting the inline content of a RichTextBlock (WinUI)
            <RichTextBlock IsTextSelectionEnabled="True" TextWrapping="Wrap">
                <Paragraph>
                    This example shows how to add a host object to the WebView. See <Hyperlink
                        FontWeight="SemiBold"
                        NavigateUri="https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.addhostobjecttoscript"
                        UnderlineStyle="None">
                        here
                    </Hyperlink>
                    for more details about the AddHostObjectToScript API.</Paragraph>
                <Paragraph />
                <Paragraph>
                    Using AddHostObjectToScript in a UWP app requires a different approach then the .NET based injection. See <Hyperlink
                        FontWeight="SemiBold"
                        NavigateUri="https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/winrt-from-js?tabs=csharp"
                        UnderlineStyle="None">
                        here
                    </Hyperlink>
                    for more details.</Paragraph>
            </RichTextBlock>
  1. See the spaces between See and the <Hyperlink are removed! They are significant in this context!

Expected behavior
Don't remove significant whitespace in Content text.

External Configuration
If you are using an external configuration, please attach to help reproduce the issue.

Version Info (please complete the following information):

  • OS: Windows 11 22631.4037
  • Visual Studio: VS 2022 17.11.1
  • XAML Styler: Extension 3.2404.2
@grochocki
Copy link
Contributor

Please take a look at this section of the wiki on how we handle whitespace. There is this concept of "significant whitespace" in XAML that we need to maintain when formatting. If you are mixing inline-level flow content elements with other text (as in your example), you will want to specify xml:space="preserve" to preserve whitespace properly.

@michael-hawker
Copy link
Contributor Author

Thanks Dave, I don't think I knew about that attribute. 😲 This was from some sample other code I was using, so was confused initially by what was happening (thought it was a bug in VS at first until I remembered XAML Styler).

I'll have to see how that gets handled with the other indentation here and the output. 🤔

Adding xml:space="preserve" to the Paragraph elements does ensure that the space isn't removed on save. 🙂 But then the rest of the insignificant indentation whitespace gets included in the app rendering:

image

Which is a bit counter-intuitive these days with how C# handles raw-string indentation.

Any whitespace to the left of the closing quotes is removed from all lines of the raw string literal.

Though I would imagine this would be now a XAML Compiler thing where if it detects xml:space="preserve" on an element that it could do similar whitespace clean-up, but that'd be a breaking change in behavior...

Hmm... how do we get both worlds? 😅

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

No branches or pull requests

2 participants