偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Visual Studio實(shí)現(xiàn)JS代碼折疊功能

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

環(huán)境

Microsoft Visual Studio 2008

正文

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

打開宏資源管理器

2.      創(chuàng)建一個新模塊

創(chuàng)建新模塊

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.         '農(nóng)民伯伯 --- 自動為"http://#endregion"結(jié)束的代碼添加***一行,不然出錯  
  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 

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

注意我加的代碼段,如果不加,并且你的JS***一行為#endregion,宏將報(bào)錯,顯示“值不在預(yù)期的范圍內(nèi)”。

4.設(shè)置快捷鍵

設(shè)置快捷鍵

 

4.1工具 -> 選項(xiàng) - > 環(huán)境 -> 鍵盤

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

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

5.效果

5.1輸入代碼:

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

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

js編輯框顯示效果

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

效果

 

結(jié)束

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

【編輯推薦】

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

2011-02-28 10:27:41

Visual Stud

2012-04-25 11:04:13

Visual Stud

2010-12-14 09:15:50

Visual Stud

2013-11-13 10:07:26

Visual Stud微軟

2012-09-19 10:14:12

Visual Stud

2010-04-12 08:43:45

Visual Stud

2013-06-04 17:08:19

Visual Stud

2009-12-18 09:49:28

Visual Stud

2009-12-04 16:57:52

Visual Stud

2009-10-22 09:47:33

Visual Stud

2009-07-01 17:11:32

標(biāo)記導(dǎo)航Visual Stud

2009-04-23 14:05:28

Visual Stud歷史調(diào)試功能

2009-12-14 17:44:39

Visual Stud

2013-08-01 15:12:03

Visual Stud

2023-09-26 00:24:44

VisualStudio視圖

2009-11-05 09:42:42

Visual Stud

2009-11-19 10:55:33

Visual Stud

2010-07-05 09:46:42

Visual Stud

2009-08-21 13:29:20

Visual Stud

2013-11-15 10:21:56

Visual StudEditor
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號