如何防止 Visual Studio 编辑器在遇到断点时自动水平滚动
在 Visual Basic 中(我在 2005 年和 2008 年见过这种情况),当您命中断点或单步并且该行上的代码延伸到屏幕末尾时,窗口会自动向右滚动,以便尽可能多的行可见尽可能。我明白为什么这可能有用,但我发现它有点分散注意力,因为在我尝试调试时屏幕似乎经常跳来跳去。此外,代码的上下文可能会被切断,因此如果有一些嵌套循环、ifs 等,那么代码的其余部分可能完全在屏幕外,这令人沮丧。
有谁知道如何禁用这种行为?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是一个精确的解决方案,但您可以通过单击行号旁边的细垂直代码折叠/轮廓线来将行重新颠倒。比向下滚动条稍微好一些。这是在 VS 2015 中。
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.
您可以按住 ctrl 按钮并向下滚动以缩小,以便在代码视图中查看文档的更多内容。这样做会使字体变小。
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.
您应该尽量避免编写超出屏幕边缘的代码。
这不仅使调试变得更加困难,而且当其他人尝试阅读您的代码时,这也非常困难且令人沮丧。
您不应该深入嵌套到任何循环中,而应该否定您的条件并使用中断/返回/转义。
因此,而不是这样: 相反
,你应该这样做:
此外,像 linq 语句/表达式这样的东西应该被分成块
以便于可读,而不是:
这会导致你的问题,而是这样做:
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:
Instead you should do this:
Furthermore things like linq statements / expressions should be broken into chunks to be readable
rather then:
Which causes your problem, instead do it like this: