Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Does anyone know of a VS2010 extension for CSS regions? I have some pretty big CSS files and I can't seem to locate how to create regions for these. I have a JavaScript region extension but not one for CSS?

share|improve this question
    
I have the same inquiry. I logged this issue at connect.microsoft.com - connect.microsoft.com/VisualStudio/feedback/details/582149/…. I got a message saying the issue was resolved, but nothing further. Not sure what that all meant? Perhaps they've released an extension for it? I'm quite lost. –  jonathanconway Aug 15 '10 at 6:47
add comment

3 Answers

You could try the JavaScript collapse macro and change the //#region for /*#region*/

Check http://blog.devarchive.net/2008/04/using-region-directive-with-javascript.html.

Of course you should create a new macro and copy/paste the same script.

Option Strict Off
Option Explicit Off

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.Collections

Public Module JsMacros

Sub OutlineCssRegion()
    Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection

    'Const REGION_START As String = "//#region"
    'Const REGION_END As String = "//#endregion"
    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
share|improve this answer
add comment

This is an old post, but I thought I'd follow up since it still appears as a top result in Google (VS CSS Regions).

See http://jse.codeplex.com/ - this extension allows for class and region collapsing with CSS files within VS 2010.

Example:

/* #region Generic class collection */

.GenericClass {
    border: 1px solid #000000;
    }

.GenericClass2 {
    border: 2px solid #000000;
    }

/* #endregion */
share|improve this answer
add comment

This feature has finally made it to Visual Studio 2012. :)

Usage is as @Bjorn Aadnesgaard describes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.