Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 502763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:19:29+00:00 2026-05-13T06:19:29+00:00

How can you implement regions a.k.a. code collapse for JavaScript in Visual Studio? If

  • 0

How can you implement regions a.k.a. code collapse for JavaScript in Visual Studio?

If there are hundreds of lines in javascript, it’ll be more understandable using code folding with regions as in vb/C#.

#region My Code

#endregion
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:19:29+00:00Added an answer on May 13, 2026 at 6:19 am

    Blog entry here explains it and this MSDN question.

    You have to use Visual Studio 2003/2005/2008 Macros.

    Copy + Paste from Blog entry for fidelity sake:

    1. Open Macro Explorer
    2. Create a New Macro
    3. Name it OutlineRegions
    4. Click Edit macro and paste the following VB code:
    Option 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
    
    1. Save the Macro and Close the Editor
    2. Now let’s assign shortcut to the macro. Go to Tools->Options->Environment->Keyboard and search for your macro in “show commands containing” textbox
    3. now in textbox under the “Press shortcut keys” you can enter the desired shortcut. I use Ctrl+M+E. I don’t know why – I just entered it first time and use it now 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 258k
  • Answers 258k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This sounds like a good approach. You can diff various… May 13, 2026 at 11:02 am
  • Editorial Team
    Editorial Team added an answer Here: ProcessBuilder processbuilder try { processbuilder.directory(file); processbuilder.redirectErrorStream(true); process = processbuilder.start();… May 13, 2026 at 11:02 am
  • Editorial Team
    Editorial Team added an answer Change where (s.crmc_Retail_Trade_Id == tradeId) to where (s.crmc_Retail_Trade_Id == tradeId… May 13, 2026 at 11:01 am

Related Questions

I have a control that inherits from TreeView (System.Windows.Controls.TreeView from WPF Framework) and it
My question is about passing data from kernel to a user space program. I
All paint programs, independent of how simple or complex they are, come with a
Will you please provide me a reference to help me understand how scanline based
I am trying to create a simple visualization of what my code does. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.