html – 如何在Visual Studio中移动自动完成的关闭标签

前端之家收集整理的这篇文章主要介绍了html – 如何在Visual Studio中移动自动完成的关闭标签前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使Visual Studio自动完成的结束标签移动到右边一个单词(或更多).例如,给出以下 HTML
<p>I need to emphasize some text.</p>

如果我键入< em>在“强调”之前,Visual Studio自动完成如下:

<p>I need to <em></em>emphasize some text.</p>

然后我需要移动关闭< / em>得到我想要的:

<p>I need to <em>emphasize</em> some text.</p>

有没有办法使Visual Studio自动执行最后一步?

解决方法

@H_502_17@ 你的问题让我想到如果这个功能存在的话会很酷.幸运的是,在VS中实现宏是非常简单的.下面是宏的代码.您可以使用VS中的自定义工具轻松地将其绑定到CTRL ALT.

(注意:我刚刚把它扔在一起,就是星期五晚上)

Sub MoveClosingTag()
    Dim ts As EnvDTE.TextSelection = CType(DTE.ActiveDocument.Selection(),EnvDTE.TextSelection)
    Dim start As EditPoint = ts.ActivePoint.CreateEditPoint()
    Dim tag As String

    ts.WordRight(True)
    If ts.Text = "</" Then
        Do Until ts.ActivePoint.AtEndOfLine
            ts.CharRight(True)
            If ts.Text.EndsWith(">") Then Exit Do
        Loop
        tag = ts.Text
        If tag.EndsWith(">") Then
            ts.Delete()
            ts.WordRight(False)
            ts.Insert(tag,EnvDTE.vsInsertFlags.vsInsertFlagsCollapseToStart)
        Else
            ts.MoveToPoint(start)
        End If
    Else
        ts.MoveToPoint(start)
    End If
End Sub
原文链接:https://www.f2er.com/html/224545.html

猜你在找的HTML相关文章