0

When facing the notorious newline problem after switching from C# to VB.NET,

You inevitably attempt to fix your mistake with a quick undo (ctrl + z). However it does not undo the newline but instead just deletes the white space that precedes your cursor. It makes you Undo twice to get the effect you were hoping for.

Here is a video that shows what I am talking about: http://youtu.be/K2IPrLB4gWA

Why does the Undo behave the way it does?

Community
  • 1
  • 1
jth41
  • 3,808
  • 9
  • 59
  • 109
  • 2
    Perhaps it has something to do with the way windows does the newline (linefeed and Carriage return) check out this [link](http://stackoverflow.com/questions/7013034/does-windows-carriage-return-r-n-consist-of-two-characters-or-one-character) – Jeremy Lin Jul 29 '13 at 19:17
  • 1
    I was blown away when I went to my own copy of visual studio to discover that it does the same thing. I never ever noticed this before. – Steven Liekens Jul 30 '13 at 02:14

1 Answers1

2

What you are seeing is an effect of the VB.Net Pretty Printing engine. On certain events like Enter the IDE will attempt to format your code. This will be done as a separate undo action. Hence the next undo will undo the pretty print, not the actual code that you typed. In this particular case a set of spaces is being added for pretty printing and hence you are undoing that action

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • I am afraid it didnt work for me when I turned off pretty printing: http://stackoverflow.com/questions/17934038/is-there-any-way-to-turn-off-pretty-printing-in-the-vs2010-ide?lq=1 – jth41 Jul 29 '13 at 21:55
  • @jth41 it's possible the indent behavior is not a part of the pretty printing logic and is just standard indent logic which can't be turned off. I'll have to look into that – JaredPar Jul 29 '13 at 22:20