成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Visual Studio實現JS代碼折疊功能

開發
Visual Studio的代碼折疊功能非常好用,#region #endregion 這個詞連搜狗的詞庫里面都出現了(不含'#'號),可見使用頻率很高,但是他不支持js的代碼折疊。最近Ext用得比較多,一寫就是上百行JS代碼,非常不方便,想著自己寫個擴展或插件什么的,已經用宏來實現了,本文可以理解為該文的簡單譯本,注意宏代碼部分我有所改動。

環境

Microsoft Visual Studio 2008

正文

1. 打開宏資源管理器:視圖 -> 其他窗口 -> 宏資源管理器 

打開宏資源管理器

2.      創建一個新模塊

創建新模塊

3.編輯宏:選中模塊 -> 右鍵編輯

  1. Option Strict Off  
  2. Option Explicit Off  
  3. Imports System  
  4. Imports EnvDTE  
  5. Imports EnvDTE80  
  6. Imports System.Diagnostics  
  7. Imports System.Collections  
  8. Public Module JsMacros  
  9.     Sub OutlineRegions()  
  10.         Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection  
  11.         Const REGION_START As String = "http://#region" 
  12.         Const REGION_END As String = "http://#endregion" 
  13.         selection.SelectAll()  
  14.         '農民伯伯 --- 自動為"http://#endregion"結束的代碼添加***一行,不然出錯  
  15.         If selection.Text.EndsWith(REGION_END) Then  
  16.             selection.EndOfLine()  
  17.             selection.NewLine()  
  18.             selection.SelectAll()  
  19.         End If  
  20.         Dim text As String = selection.Text  
  21.         selection.StartOfDocument(True)  
  22.         Dim startIndex As Integer  
  23.         Dim endIndex As Integer  
  24.         Dim lastIndex As Integer = 0 
  25.         Dim startRegions As Stack = New Stack()  
  26.         Do  
  27.             startIndex = text.IndexOf(REGION_START, lastIndex)  
  28.             endIndex = text.IndexOf(REGION_END, lastIndex)  
  29.             If startIndex = -1 AndAlso endIndex = -1 Then  
  30.                 Exit Do  
  31.             End If  
  32.             If startIndex <> -1 AndAlso startIndex < endIndex Then  
  33.                 startRegions.Push(startIndex)  
  34.                 lastIndex = startIndex + 1  
  35.             Else  
  36.                 ' Outline region   
  37.                 selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)  
  38.                 selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)  
  39.                 selection.OutlineSection()  
  40.                 lastIndex = endIndex + 1  
  41.             End If  
  42.         Loop  
  43.         selection.StartOfDocument()  
  44.     End Sub  
  45.     Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)  
  46.         Dim lineNumber As Integer = 1 
  47.         Dim i As Integer = 0 
  48.         While i < index 
  49.             If text.Chars(i) = vbCr Then  
  50.                 lineNumber += 1  
  51.                 i += 1  
  52.             End If  
  53.             i += 1  
  54.         End While  
  55.         Return lineNumber  
  56.     End Function  
  57. End Module 

保存即可。這里可以省去新建宏的步驟,他會根據代碼自動給你生成一個宏的。

注意我加的代碼段,如果不加,并且你的JS***一行為#endregion,宏將報錯,顯示“值不在預期的范圍內”。

4.設置快捷鍵

設置快捷鍵

 

4.1工具 -> 選項 - > 環境 -> 鍵盤

4.2在顯示命令包含下面的文本框中輸入宏名outli,不用輸全,下面能顯示你新建的宏

4.3點一下 按快捷鍵 下面的文本框, 然后自定義快捷鍵組合,我定義的是Ctrl+M,Ctrl+J,點分配(別忘了!),點確定。

5.效果

5.1輸入代碼:

  1. //aasdsadsad  
  2. //#region  
  3. //#endregion 

5.2快捷鍵Ctrl+M,Ctrl+J啟動宏,能看到系統的右下角顯示可愛的小方塊在轉動,js編輯框顯示效果如下:

js編輯框顯示效果

5.3之后就可以用快捷鍵Ctrl+M,Ctrl+L來[展開/折疊]代碼了,注意關閉之后重新打開需要再啟動一次宏,展開效果如下:

效果

 

結束

想到不如做到,但做之前要是能先Google一下也許能事半功倍。

【編輯推薦】

  1. Visual Studio 2010 Beta 1安裝和調試
  2. Visual Studio 2010的微軟云平臺擴展發布
  3. Visual Studio 2010 Beta1試用手記
  4. Visual Studio 2010重要新功能一覽
  5. 使用Visual Studio 2008調試器
責任編輯:彭凡 來源: CSDN博客
相關推薦

2011-02-28 10:27:41

Visual Stud

2012-04-25 11:04:13

Visual Stud

2013-11-13 10:07:26

Visual Stud微軟

2010-12-14 09:15:50

Visual Stud

2012-09-19 10:14:12

Visual Stud

2013-06-04 17:08:19

Visual Stud

2009-12-18 09:49:28

Visual Stud

2010-04-12 08:43:45

Visual Stud

2009-04-23 14:05:28

Visual Stud歷史調試功能

2009-12-14 17:44:39

Visual Stud

2013-08-01 15:12:03

Visual Stud

2023-09-26 00:24:44

VisualStudio視圖

2009-12-04 16:57:52

Visual Stud

2009-10-22 09:47:33

Visual Stud

2009-07-01 17:11:32

標記導航Visual Stud

2009-11-05 09:42:42

Visual Stud

2009-11-19 10:55:33

Visual Stud

2013-11-15 10:21:56

Visual StudEditor

2012-09-17 13:49:31

2009-11-02 14:06:59

Visual Stud
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产成人一区二区三区久久久 | 国产一区999 | 国产福利视频导航 | 久久精品一级 | 九色www| 国产极品粉嫩美女呻吟在线看人 | 久久精品成人一区 | 亚洲国产精品网站 | 欧美精品一区免费 | 亚洲精品欧美一区二区三区 | 中文字幕亚洲精品 | 99久久免费精品国产男女高不卡 | 男人的天堂avav | 中文字幕在线一区二区三区 | 久久精品欧美一区二区三区不卡 | 日韩aⅴ在线观看 | 久草网址| 精品日韩一区二区 | 色嗨嗨 | 欧美高清免费 | 日韩在线精品视频 | 亚洲网址在线观看 | 久久毛片| 国产免费观看一级国产 | 色资源站 | 国产日韩精品视频 | 国产免费播放视频 | 亚洲精品一区中文字幕 | 国产二区三区 | 国产又色又爽又黄又免费 | 91精品国产一区二区三区香蕉 | 亚洲高清电影 | 伊人久久伊人 | 日本久久综合 | 久久av网站 | 日韩成人在线观看 | 日韩欧美一区在线 | 日韩综合在线视频 | 在线免费观看a级片 | 国产视频第一页 | 日韩一区二区久久 |