[英]Shortcut for uncommenting CSS in VS 2008?
只需编写一个类似的模块/方法,我认为应该可以,但我没有尝试过,但这就是我的想法。
请将此视为您已链接的帖子的补充,您可以从该帖子中查找其他详细信息。
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的代码颜色,但是他提供的选项似乎很方便。 另外,在上面提供的链接中,他解释了所有有关如何绑定快捷键以使其正常工作的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.