VS2008中取消CSS注释的快捷方式?
我使用中提到的宏在VS2008的CSS编辑器中对文本选择进行注释。我正在寻找另一个取消注释注释的宏。只需编写一个类似的模块/方法,我认为应该可以,我还没有尝试过,但这就是我的想法。VS2008中取消CSS注释的快捷方式?,css,visual-studio,visual-studio-2008,editor,Css,Visual Studio,Visual Studio 2008,Editor,我使用中提到的宏在VS2008的CSS编辑器中对文本选择进行注释。我正在寻找另一个取消注释注释的宏。只需编写一个类似的模块/方法,我认为应该可以,我还没有尝试过,但这就是我的想法。 请把这看作是你链接到的帖子的补充,你可以从那个帖子中寻找其他的细节。 Public Module UnCommentCSS Sub UnCommentCSS() Dim selection As TextSelection selection = DTE.ActiveDocum
请把这看作是你链接到的帖子的补充,你可以从那个帖子中寻找其他的细节。
Public Module UnCommentCSS
Sub UnCommentCSS()
Dim selection As TextSelection
selection = DTE.ActiveDocument.Selection
Dim selectedText As String
selectedText = selection.Text
If selectedText.Length > 0 _
and selectedText.StartsWith("/*") _
and selectedText.EndsWith("*/") Then
selectedText = selectedText.Split("*"c)
selection.Text = selectedText(1)
End If
End Sub
End Module
注意:如果在/***/否则,您必须进行必要的改进/更改正如IObservable的Brian Schmitt所说,您可以使用相同的键对代码进行注释和取消注释,当然这取决于代码是否已注释。他用于实现这一目标的代码如下:
Sub CommentCSS()
If Not DTE.ActiveDocument.Name.EndsWith("css") Then Return
Try
DTE.UndoContext.Open("Comment CSS")
Dim txtSel As TextSelection = DTE.ActiveDocument.Selection
Dim currText As String = txtSel.Text
If currText.Length > 0 Then
Dim newTxt As String
If currText.Trim.StartsWith("/*") AndAlso currText.Trim.EndsWith("*/") Then
newTxt = currText.Replace("/*", "").Replace("*/", "")
Else
newTxt = "/*" + currText + "*/"
End If
txtSel.Delete()
txtSel.Insert(newTxt, vsInsertFlags.vsInsertFlagsInsertAtEnd)
End If
Finally
DTE.UndoContext.Close()
End Try
End Sub
我从代码中删除了他的注释,因为它们弄乱了SO的代码着色,但他给出的选项似乎非常方便。此外,在上面提供的链接中,他解释了如何绑定快捷键以使其正常工作