razor icon indicating copy to clipboard operation
razor copied to clipboard

Visual Studio 2022 V 17.9.0 Preview 2 Inserts Lines after @ in Blazor Server App

Open vsfeedback opened this issue 1 year ago • 1 comments

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] While editing a . Razor component that has similar code to the following:

<td align="right">@li.Qty.ToString("0.00")</td>
<td align="right">@li.Rate.ToString("$0.00")</td>
<td align="right">@(li.Disc * 100)%</td>

if in the @code section you create a new function:

private void MyFunc()
{}

when you press enter in between the {} to insert your code, it wreaks havoc on the blazor code above that has the @. It changes it to:

                <td align="right">@
                    li.Rate.ToString("
.00")
                </td>

thus creating errors in your code as shown on image: image.png

In order to temporarily correct the situation, immediately after the error occurs, you can press Ctrl-Z to undo only ONCE and it will allow you to continue. More of an annoyance than a bug. I assume it must be related to the new Razor intellisense/handling, but I am not sure.


Original Comments

Feedback Bot on 12/13/2023, 05:19 PM:

(private comment, text removed)

Mariano J. Padilla on 12/14/2023, 07:30 AM:

(private comment, text removed)

Feedback Bot on 1/31/2024, 04:50 PM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Feb 05 '24 18:02 vsfeedback

The $0 seems to be what is triggering the bug. I was able to reproduce this error consistently on visual studio. When I hit"Enter" on the keyboard, auto-format does its job and the position of the cursor and the $0 get flipped.

https://github.com/dotnet/razor/assets/17770319/609191ce-09da-4da3-895a-8eb5b15c6c1c

jordi1215 avatar Feb 05 '24 18:02 jordi1215