Visual Studio,“仅折叠/扩展区域"快捷方式 [英] Visual Studio, Collapse/Extends Regions ONLY shortcut
问题描述
是否仅存在折叠/展开区域的快捷方式?意思是,如果我有一个包含5种方法的区域,并且我击中了塌陷,那么该区域将塌陷,当我击中expand时,该区域将扩展,并且我将看到所有5种方法的状态与以前相同(折叠/展开).
Is there any shortcut to collapse/expand the regions ONLY? Meaning, if I have a region with 5 methods in it, and I hit collapse, the region will collapse, and when I will hit expand, the region will expand and I will see all 5 methods with the same state as it was before (collapsed/expanded).
目前,我发现的快捷方式可折叠ALL,或展开ALL,或将"All"一词替换为"Current"一词.
Currently the shortcuts I found collapse ALL, or expand ALL, or substitutes the "All" word for the "Current" word.
我正在寻找只折叠区域的快捷方式,而不会对区域内的其他块做任何事情.扩展也是一样.
I'm looking for a shortcut that will collapse only regions, and will not do anything to the other blocks inside a region. Same thing with expanding.
如果没有这样的东西,也许有人找到了视觉扩展来做到这一点?
If there is no such thing, maybe someone found some visual extension to do it?
欢呼 卢卡斯
推荐答案
您可以使用以下宏扩展/折叠区域,而各个方法的扩展/折叠状态保持不变.
You can use the following macros to expand/collapse the regions while leaving the expand/collapse state of individual methods as they were.
我在此处一个>.请注意,我必须注释掉CollapseAllRegions方法中对objSelection.EndOfDocument()的调用,以使其正常工作(使用Visual Studio 2010)
I found the macro here. Note that I had to comment out the call to objSelection.EndOfDocument() from the CollapseAllRegions method for it to work properly (using 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,“仅折叠/扩展区域"快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!