【问题标题】:Shortcut for uncommenting CSS in VS 2008?在 VS 2008 中取消注释 CSS 的快捷方式?
【发布时间】:2009-10-19 06:09:57
【问题描述】:

我使用this question 中提到的宏在 VS 2008 中的 CSS 编辑器中注释文本选择。我正在寻找另一个取消 cmets 的宏。

【问题讨论】:

    标签: css visual-studio visual-studio-2008 editor


    【解决方案1】:

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

    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
    

    注意:如果 /* */ 之间没有嵌套 *,则此方法有效 否则,您必须进行必要的改进/更改

    【讨论】:

      【解决方案2】:

      作为 IObservable suggests 的 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
      

      我从代码中删除了他的 cmets,因为他们弄乱了 SO 的代码颜色,但他提供的选项似乎很方便。此外,在上面提供的链接中,他解释了如何绑定快捷键以使其正常工作。

      【讨论】:

        猜你喜欢
        • 2011-01-01
        • 2017-10-29
        • 1970-01-01
        • 2019-04-03
        • 2014-07-20
        • 2015-12-31
        • 1970-01-01
        • 1970-01-01
        • 2018-12-25
        相关资源
        最近更新 更多