如何防止 Visual Studio 编辑器在遇到断点时自动水平滚动

发布于 2024-09-11 03:02:39 字数 224 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嗫嚅 2024-09-18 03:02:39

这不是一个精确的解决方案,但您可以通过单击行号旁边的细垂直代码折叠/轮廓线来将行重新颠倒。比向下滚动条稍微好一些。这是在 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.

秋意浓 2024-09-18 03:02:39

您可以按住 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.

旧竹 2024-09-18 03:02:39

您应该尽量避免编写超出屏幕边缘的代码。

这不仅使调试变得更加困难,而且当其他人尝试阅读您的代码时,这也非常困难且令人沮丧。

您不应该深入嵌套到任何循环中,而应该否定您的条件并使用中断/返回/转义。

因此,而不是这样: 相反

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

,你应该这样做:

if (!condition) return;
//do stuff

if (!anotherCondition) return;
//more stuff

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

此外,像 linq 语句/表达式这样的东西应该被分成块

以便于可读,而不是:

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

这会导致你的问题,而是这样做:

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文