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

发布于 2024-08-08 08:31:30 字数 156 浏览 1 评论 0原文

我使用这个问题中提到的宏来评论文本选择VS 2008 中的 CSS 编辑器。我正在寻找另一个取消注释的宏。

I used the macro mentioned in this question to comment a text selection in the CSS editor in VS 2008. I am looking for another macro which uncomments comments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-08-15 08:31:30

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

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

注意:如果 /* */ 之间没有嵌套 *,则此方法有效
否则你必须做出必要的改进/改变

Just write a similar module/method, I think that should work, I haven't tried, but this is what I think.
Please consider this as addition to the post that you have linked, you can look for the other details from that post.

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

Note: this works if you have no nested * in between /* */
Otherwise you have to make necessary improvements/changes

日裸衫吸 2024-08-15 08:31:30

正如 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 的代码着色,但他提供的选项似乎非常方便。此外,在上面提供的链接中,他解释了如何绑定快捷键以使其正常工作。

As Brian Schmitt of IObservable suggests, you could use the same key to comment and uncomment your code, depending of course on whether or not it's already commented. The code he uses to achieve this is the following:

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

I removed his comments from the code as they messed up SO's code coloring, but the option that he gives seems pretty convenient. Also, in the link provided above, he explains all about how to bind the shortcut keys to make it work right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文