您的位置:首页 > Web前端 > JavaScript

Using #region Directive With JavaScript Files in Visual Studio

2012-07-13 10:15 861 查看
本文转载自:http://blog.devarchive.net/2008/04/using-region-directive-with-javascript.html

这是一个不错的小创意,可以针对大量的javascript脚本实现#region管理的效果.创意无限啊,赞一个

1.首先编写以下的宏
OptionStrictOff
OptionExplicitOff

ImportsSystem
ImportsEnvDTE
ImportsEnvDTE80
ImportsSystem.Diagnostics
ImportsSystem.Collections

PublicModuleJsMacros

SubOutlineRegions()
DimselectionAsEnvDTE.TextSelection=DTE.ActiveDocument.Selection

ConstREGION_STARTAsString="//#region"
ConstREGION_ENDAsString="//#endregion"

selection.SelectAll()
DimtextAsString=selection.Text
selection.StartOfDocument(True)

DimstartIndexAsInteger
DimendIndexAsInteger
DimlastIndexAsInteger=0
DimstartRegionsAsStack=NewStack()

Do
startIndex=text.IndexOf(REGION_START,lastIndex)
endIndex=text.IndexOf(REGION_END,lastIndex)

IfstartIndex=-1AndAlsoendIndex=-1Then
ExitDo
EndIf

IfstartIndex<>-1AndAlsostartIndex<endIndexThen
startRegions.Push(startIndex)
lastIndex=startIndex+1
Else
'Outlineregion...
selection.MoveToLineAndOffset(CalcLineNumber(text,CInt(startRegions.Pop())),1)
selection.MoveToLineAndOffset(CalcLineNumber(text,endIndex)+1,1,True)
selection.OutlineSection()

lastIndex=endIndex+1
EndIf
Loop

selection.StartOfDocument()
EndSub

PrivateFunctionCalcLineNumber(ByValtextAsString,ByValindexAsInteger)
DimlineNumberAsInteger=1
DimiAsInteger=0

Whilei<index
Iftext.Chars(i)=vbCrThen
lineNumber+=1
i+=1
EndIf

i+=1
EndWhile

ReturnlineNumber
EndFunction

EndModule

2.然后指派一个快捷键给它




这里的快捷键是无所谓的,但一定要两个键



3.然后假设我们有这样的页面





此时,如果按下CTRL+M+,





的确是挺不错的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: