是否有任何快捷方式可以折叠/扩展区域?意思是,如果我有一个包含5个方法的区域,并且我遇到崩溃,那么该区域将会崩溃,当我将命中展开时,该区域将会扩展,我将看到所有5个方法具有与之前相同的状态(折叠/展开)。
目前我找到的快捷键会折叠ALL,或展开ALL,或用“全部”字代替“当前”字。
我正在寻找一种只会折叠区域的快捷方式,并且不会对区域内的其他区块做任何事情。与扩张相同的事情。
如果没有这样的东西,也许有人找到了一些视觉延伸来做到这一点?
欢呼声 卢卡斯
答案 0 :(得分:10)
为什么不简单地点击
ctrl + m + m
光标在#region regionname
答案 1 :(得分:4)
您可以使用以下宏来展开/折叠区域,同时保留各个方法的展开/折叠状态。
我找到了宏here。请注意,我必须从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
答案 2 :(得分:3)
我已经编写了一个免费的Visual Studio扩展程序" Menees VS Tools"为"折叠所有区域提供命令"和"扩展所有地区"。它适用于2003年至2013年的VS版本.Visual Studio中提供了VS 2013和VS 2012版本。