Skip to content

"format document" does not work properly in Blazor razor #11873

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

Open
PhilippJR opened this issue May 20, 2025 · 2 comments
Open

"format document" does not work properly in Blazor razor #11873

PhilippJR opened this issue May 20, 2025 · 2 comments

Comments

@PhilippJR
Copy link

A couple of weeks ago, I reported, that formatting documents does not work properly, when in Razor, there is a textarea inside of a code block. Please see here.

The issue was marked as fixed with VS 17.14, but at least for me, 17.14 made it worse. Now, not only textareas are misplaced but also span closing tags and some lines with line breaks.

17.14.mp4

For reproduction, I copied my code to Home.razor of a new Blazor Wasm project, deleted some things and replaced classes that did not exist. CTRL+k,d resulted in the same misformatted file. Please try yourself. Simply paste below code that I formatted by hand. Then, hit CTRL+k,d or already see what's wrong when "format on paste" is activated.
After the first "misplacement" of some elements, CTRL+k,d still moves the textarea closing tag, what I thought should have been fixed with 17.14.

@page "/"
@using System.Globalization

@if (true)
{
    <div class="d-flex">
        <div class="data-box-column">
            @if (true)
            {
                <span>foo:</span>
                <span>bar:</span>
                <hr class="my-1" />
            }
            <span>baz:</span>
        </div>
        <div class="d-flex flex-column" style="text-align: end;">
            <textarea id="modifiedPrice" disabled="@(!true)" maxlength="10" rows="1" @bind="String1" oninput="if(this.value.includes('\n')) modifiedPrice.blur()"></textarea>
            @if (true)
            {
                <span>
                    @((((true) ? 123d : 0d) +
                        (true ? 123d : 0d)
                        ).ToString("F2", CultureInfo.InvariantCulture)) €
                </span>
                <hr class="my-1" />
                <span>
                    @((123d +
                        ((true) ? 123d : 0d) +
                        (true ? 123d : 0d)
                        ).ToString("F2", CultureInfo.InvariantCulture)) €
                </span>
            }
        </div>
    </div>
    <div class="d-flex flex-column mt-2">
        <label class="small" for="foo">
            <textarea id="foo"
                      disabled="@(!true)"
                      maxlength="56"
                      rows="1"
                      placeholder="@String2"
                      @bind="String3"
                      oninput="if(this.value.includes('\n')) { this.value = this.value.replace(/\n/g, ''); this.blur(); }">
            </textarea>
        </label>
    </div>
}
else
{
    <span>@String4</span>
}


@code {
    private string String1 { get; set; } = string.Empty;
    private string String2 { get; set; } = string.Empty;
    private string String3 { get; set; } = string.Empty;
    private string String4 { get; set; } = string.Empty;
}
@anan1213095357
Copy link

Has it been resolved? Are there any latest developments? I found that many situations affect the layout arrangement. Including server's @OnClick='the inline function layout here is all messy/disordered'

@PhilippJR
Copy link
Author

Has it been resolved?

What exactly? Probably not. As mentioned above, it is worse with 17.14.

Are there any latest developments? I found that many situations affect the layout arrangement. Including server's @OnClick='the inline function layout here is all messy/disordered'

I do not understand, what you want to tell me.

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

3 participants