繁体   English   中英

在VS 2008中取消注释CSS的快捷方式?

[英]Shortcut for uncommenting CSS in VS 2008?

我使用了此问题中提到的宏来注释VS 2008中CSS编辑器中的文本选择。我正在寻找另一个不注释注释的宏。

只需编写一个类似的模块/方法,我认为应该可以,但我没有尝试过,但这就是我的想法。
请将此视为您已链接的帖子的补充,您可以从该帖子中查找其他详细信息。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM