如何在 Visual Studio 中为 JavaScript 实现区域又名代码折叠?
如果 javascript 中有数百行,那么在 vb/C# 中使用带有区域的代码折叠会更容易理解。
#region My Code
#endregion
如何在 Visual Studio 中为 JavaScript 实现区域又名代码折叠?
如果 javascript 中有数百行,那么在 vb/C# 中使用带有区域的代码折叠会更容易理解。
#region My Code
#endregion
对于正在使用最新版本的 Visual Studio 的开发人员来说是个好消息
该网站要点都具有此功能的到来。
注意:对于 VS 2017 使用JavaScript 区域: https : //marketplace.visualstudio.com/items?itemName=MadsKristensen.JavaScriptRegions
Microsoft 现在为VS 2010提供了一个扩展,可以提供以下功能:
这很容易!
标记要折叠的部分,然后,
Ctrl+M+H
并扩展使用其左侧的“+”标记。
对于那些即将使用 Visual Studio 2012 的人,存在Web Essentials 2012
对于那些即将使用 Visual Studio 2015 的人,存在Web Essentials 2015.3
用法与@prasad 所问的完全一样
您必须使用 Visual Studio 2003/2005/2008 宏。
为了保真,从博客条目中复制 + 粘贴:
OutlineRegionsOption Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.Collections
Public Module JsMacros
    Sub OutlineRegions()
        Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
        Const REGION_START As String = "//#region"
        Const REGION_END As String = "//#endregion"
        selection.SelectAll()
        Dim text As String = selection.Text
        selection.StartOfDocument(True)
        Dim startIndex As Integer
        Dim endIndex As Integer
        Dim lastIndex As Integer = 0
        Dim startRegions As Stack = New Stack()
        Do
            startIndex = text.IndexOf(REGION_START, lastIndex)
            endIndex = text.IndexOf(REGION_END, lastIndex)
            If startIndex = -1 AndAlso endIndex = -1 Then
                Exit Do
            End If
            If startIndex <> -1 AndAlso startIndex < endIndex Then
                startRegions.Push(startIndex)
                lastIndex = startIndex + 1
            Else
                ' Outline region ...
                selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)
                selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)
                selection.OutlineSection()
                lastIndex = endIndex + 1
            End If
        Loop
        selection.StartOfDocument()
    End Sub
    Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)
        Dim lineNumber As Integer = 1
        Dim i As Integer = 0
        While i < index
            If text.Chars(i) = vbCr Then
                lineNumber += 1
                i += 1
            End If
            i += 1
        End While
        Return lineNumber
    End Function
End Module