Sean
Sean

Reputation: 1756

How can I prevent Visual Studio editor from automatically horizontally scrolling when a breakpoint is hit

In Visual Basic (I've seen this in 2005 and 2008) when you hit a breakpoint or single step and the code on this line stretches past the end of the screen, the window automatically scrolls right so that as much of the line is visible as possible. I can see why this might be useful, but I find it a little distracting as the screen appears to jump around a lot while I'm trying to debug. Furthermore, the context of the code can be chopped off, so if there are a few nested loops, ifs etc then the rest of the code can be entirely off-screen which is frustrating.

Does anyone know how to disable this behavior?

Upvotes: 32

Views: 2478

Answers (3)

blevotroid
blevotroid

Reputation: 51

Not an exact solution, but you can bump the lines back over by clicking the thin vertical code-folding/outlining line next to the line numbers. Slightly better than going down to the scrollbar. This is in VS 2015.

Upvotes: 2

Steffen Cole Blake
Steffen Cole Blake

Reputation: 654

You should just extremely avoid writing code that goes off the edge of the screen.

Not only does this make debugging much harder, but when other people try and read your code it is very difficult and frustrating.

You shouldn't be nesting deep into any loops, but instead you should be negating your conditions and using breaks/returns/escapes.

So instead of this:

if (condition) {
   //stuff
   if (anotherCondition) {
      //more stuff
      if (yetanotherCondition) {
          //starting to get to the edge of the screen soon...
      }
    }
}

Instead you should do this:

if (!condition) return;
//do stuff

if (!anotherCondition) return;
//more stuff

if (!yetAnotherCondition) return;
//so much more room to work with!

Furthermore things like linq statements / expressions should be broken into chunks to be readable

rather then:

var foo = MyList.select(val => val.isThing() && val.isCorrect && val.hasConditions() && val.things.Any(thing => thing.isCorrect())).orderBy(val => val.property).First();

Which causes your problem, instead do it like this:

var foo = MyList.select(val => 
    val.isThing() 
    && val.isCorrect
    && val.hasConditions() 
    && val.things.Any(thing => 
        thing.isCorrect()
        )
    )
    .OrderBy(val => val.property)
    .First();

Upvotes: -1

Notch Network
Notch Network

Reputation: 1

You can hold the ctrl button and scroll down to zoom out to be able to see more of the document while you are in the code view. Doing this makes the font size smaller.

Upvotes: 0

Related Questions