是否有任何捷径可以仅折叠/展开区域?意思是,如果我有一个包含 5 个方法的区域,并且我点击折叠,该区域将崩溃,当我点击展开时,该区域将展开,我将看到所有 5 个方法的状态与以前相同(折叠/展开)。
目前我发现的快捷方式全部折叠,或展开全部,或用“全部”字代替“当前”字。
我正在寻找一个只会折叠区域的快捷方式,并且不会对区域内的其他块做任何事情。扩展也是一样。
如果没有这样的事情,也许有人找到了一些视觉扩展来做到这一点?
欢呼卢卡斯
是否有任何捷径可以仅折叠/展开区域?意思是,如果我有一个包含 5 个方法的区域,并且我点击折叠,该区域将崩溃,当我点击展开时,该区域将展开,我将看到所有 5 个方法的状态与以前相同(折叠/展开)。
目前我发现的快捷方式全部折叠,或展开全部,或用“全部”字代替“当前”字。
我正在寻找一个只会折叠区域的快捷方式,并且不会对区域内的其他块做任何事情。扩展也是一样。
如果没有这样的事情,也许有人找到了一些视觉扩展来做到这一点?
欢呼卢卡斯
为什么不简单地打
ctrl+ m+m
当光标在#region regionname
您可以使用以下宏来展开/折叠区域,同时保持各个方法的展开/折叠状态不变。
我在这里找到了宏。请注意,我必须注释掉 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
我编写了一个免费的 Visual Studio 扩展“ Menees VS Tools ”,它提供了“折叠所有区域”和“展开所有区域”的命令。它适用于 2003 到 2013 的 VS 版本。Visual Studio 库中提供了 VS 2013和 VS 2012版本。