Visual Studio,仅折叠/扩展区域快捷方式

Luc*_*cas 13 shortcut visual-studio

是否有任何快捷方式可以折叠/扩展区域?意思是,如果我有一个包含5个方法的区域,并且我遇到崩溃,那么该区域将会崩溃,当我将命中展开时,该区域将会扩展,我将看到所有5个方法具有与之前相同的状态(折叠/展开).

目前我发现的快捷键会折叠ALL,或者展开ALL,或者将"All"字替换为"Current"字样.

我正在寻找一个只会折叠区域的快捷方式,并且不会对区域内的其他区块做任何事情.扩展同样的事情.

如果没有这样的事情,也许有人找到了一些视觉扩展来做到这一点?

欢呼卢卡斯

arc*_*hil 10

为什么不简单地打

ctrl+ m+m

而光标在 #region regionname


Chr*_*lid 5

您可以使用以下宏来展开/折叠区域,同时保留各个方法的展开/折叠状态。

我在这里找到了宏。请注意,我必须注释掉CollapseAllRegions方法中对objSelection.EndOfDocument()的调用,以使其正常工作(使用Visual Studio 2010)

Imports EnvDTE
Imports System.Diagnostics
' Macros for improving keyboard support for "#region ... #endregion"
Public Module RegionTools
    ' Expands all regions in the current document
    Sub ExpandAllRegions()

        Dim objSelection As TextSelection ' Our selection object

        DTE.SuppressUI = True ' Disable UI while we do this
        objSelection = DTE.ActiveDocument.Selection() ' Hook up to the ActiveDocument's selection
        objSelection.StartOfDocument() ' Shoot to the start of the document

        ' Loop through the document finding all instances of #region. This action has the side benefit
        ' of actually zooming us to the text in question when it is found and ALSO expanding it since it
        ' is an outline.
        Do While objSelection.FindText("#region", vsFindOptions.vsFindOptionsMatchInHiddenText)
            ' This next command would be what we would normally do *IF* the find operation didn't do it for us.
            'DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        Loop
        objSelection.StartOfDocument() ' Shoot us back to the start of the document
        DTE.SuppressUI = False ' Reenable the UI

        objSelection = Nothing ' Release our object

    End Sub

    ' Collapses all regions in the current document
    Sub CollapseAllRegions()

        Dim objSelection As TextSelection ' Our selection object

        ExpandAllRegions() ' Force the expansion of all regions

        DTE.SuppressUI = True ' Disable UI while we do this
        objSelection = DTE.ActiveDocument.Selection() ' Hook up to the ActiveDocument's selection
        objSelection.EndOfDocument() ' Shoot to the end of the document

        ' Find the first occurence of #region from the end of the document to the start of the document. Note:
        ' Note: Once a #region is "collapsed" .FindText only sees it's "textual descriptor" unless
        ' vsFindOptions.vsFindOptionsMatchInHiddenText is specified. So when a #region "My Class" is collapsed,
        ' .FindText would subsequently see the text 'My Class' instead of '#region "My Class"' for the subsequent
        ' passes and skip any regions already collapsed.
        Do While (objSelection.FindText("#region", vsFindOptions.vsFindOptionsBackwards))
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion") ' Collapse this #region
            'objSelection.EndOfDocument() ' Shoot back to the end of the document for
            ' another pass.
        Loop
        objSelection.StartOfDocument() ' All done, head back to the start of the doc
        DTE.SuppressUI = False ' Reenable the UI

        objSelection = Nothing ' Release our object

    End Sub
End Module
Run Code Online (Sandbox Code Playgroud)