Visual Studio - pasting text into cshtml deletes text
Asked Answered
M

1

10

In Visual studio (2022; v: 17.2.1) when I paste some text into a cshtml file, that same text seems to get copied, but then immediately deleted; including part of existing text. This only seems to happen when overwriting jquery code (anywhere within <script> tags).

A very similar problem is already discussed here with no (usable) solution: https://developercommunity.visualstudio.com/t/when-i-copy-and-paste-what-i-paste-is-deleted-auto/367401

For example:

I have $('#tbSomeInputField1') and I copy an ID from some other control (i.e "tbSomeOtherField2") and I use the mouse to select "tbSomeInputField1" from the code and I click paste. What is left is only $()???

I'm experiencing this problem in the last couple of weeks so maybe it could be related to one of the latest VS updates...

What could be the problem?

Mauro answered 27/5, 2022 at 10:14 Comment(2)
I know this comment isn't very helpful, however editing HTML and JS in VS is a horrendous experience and has been for several versions. MS have done nothing useful to solve the various problems. I've not had the symptoms you describe though. I'd suggest disabling any extensions you have, if any, and trying again. Failing that, VS Code is very good for editing HTML and JS - far better than VS, even though that's the flagship IDE.Netta
Happens to me too, but only wehn $('#tbSomeInputField1') is followed by .method() I.e. pasting replacing "tbSomeInputField1" in $('#tbSomeInputField1') works. However, pasting replacing "tbSomeInputField1" in $('#tbSomeInputField1').val() ends up as $().val() This appears only to affect .cshtml files I'm using Microsoft Visual Studio Professional 2022, Version 17.2.2, VisualStudio.17.Release/17.2.2+32519.379Rodrigues
R
14

the answer given on visual studio community page is working well. Format on paste can be removed

Options -> Source Code -> Code Formatting -> HTML, switch to the HTML Format tab and uncheck Format on paste.

Rh answered 1/6, 2022 at 2:28 Comment(2)
This seems to do the trick. Great!Mauro
I was starting to develop a tick every time I pasted and it didn't. PS: It's Tools -> options not preference.Heredes

© 2022 - 2024 — McMap. All rights reserved.