Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在Visual Studio中移动自动完成的结束标记_Html_Visual Studio_Autocomplete - Fatal编程技术网

Html 如何在Visual Studio中移动自动完成的结束标记

Html 如何在Visual Studio中移动自动完成的结束标记,html,visual-studio,autocomplete,Html,Visual Studio,Autocomplete,我想让VisualStudio将自动完成的结束标记向右移动一个单词(或更多)。例如,给定以下HTML: <p>I need to emphasize some text.</p> 我需要强调一些文字 如果我在单词“Emphasis”之前键入,Visual Studio会自动完成如下操作: <p>I need to <em></em>emphasize some text.</p> 我需要强调一些文字 然后我需要移动关

我想让VisualStudio将自动完成的结束标记向右移动一个单词(或更多)。例如,给定以下HTML:

<p>I need to emphasize some text.</p>
我需要强调一些文字

如果我在单词“Emphasis”之前键入
,Visual Studio会自动完成如下操作:

<p>I need to <em></em>emphasize some text.</p>
我需要强调一些文字

然后我需要移动关闭按钮
,以获得我想要的:

<p>I need to <em>emphasize</em> some text.</p>
我需要强调一些文字


有没有办法让Visual Studio自动完成最后一步?

我认为这是不可能的。但是,您可以配置哪些HTML标记将自动关闭:

工具->选项->文本编辑器->HTML->格式->标记特定选项按钮->客户端HTML标记->em->结束标记->无结束标记


也请考虑自动移动结束标记不是微不足道的(应该是单词边界),它只会覆盖一个非常特殊的用例(只有一个单词应该被突出显示)。

你的问题让我思考如果这个功能存在的话会有多酷。幸运的是,在VS中作为宏实现非常简单。下面是宏的代码。您可以使用VS中的自定义工具轻松地将其绑定到CTRL+ALT+Right

注意:今天是星期五晚上,所以我很快就把它拼凑了起来)

Sub-MoveClosingTag()
将ts设置为EnvDTE.TextSelection=CType(DTE.ActiveDocument.Selection(),EnvDTE.TextSelection)
Dim起始为EditPoint=ts.ActivePoint.CreateEditPoint()
作为字符串的Dim标记
ts.WordRight(正确)
如果ts.Text=“”),则退出Do
环
tag=ts.Text
如果标记.EndsWith(“>”),则
删除(
ts.WordRight(错误)
ts.Insert(标记,EnvDTE.vsInsertFlags.vsInsertFlagsCollapseToStart)
其他的
ts.MoveToPoint(开始)
如果结束
其他的
ts.MoveToPoint(开始)
如果结束
端接头

为@w4g3n3r做这项艰苦工作提供道具。我对宏进行了一些修改,以便更好地处理空格

注意:我发现
CTRL+。
可以很好地作为这方面的快捷键;在我最初描述的用例中,您的右无名指已经位于
键上

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()
            Dim pos As Integer
            pos = ts.CurrentColumn
            ts.FindPattern(">", vsFindOptions.vsFindOptionsRegularExpression)
            If ts.CurrentColumn = pos Then
                ts.WordRight(False)
                ts.FindPattern(">", vsFindOptions.vsFindOptionsRegularExpression)
            End If
            ts.Insert(tag, EnvDTE.vsInsertFlags.vsInsertFlagsCollapseToStart)
        Else
            ts.MoveToPoint(start)
        End If
    Else
        ts.MoveToPoint(start)
    End If
End Sub
Sub-MoveClosingTag()
将ts设置为EnvDTE.TextSelection=CType(DTE.ActiveDocument.Selection(),EnvDTE.TextSelection)
Dim起始为EditPoint=ts.ActivePoint.CreateEditPoint()
作为字符串的Dim标记
ts.WordRight(正确)
如果ts.Text=“”),则退出Do
环
tag=ts.Text
如果标记.EndsWith(“>”),则
删除(
作为整数的Dim pos
pos=ts.CurrentColumn
ts.FindPattern(“>”,vsFindOptions.vsFindOptions规则表达式)
如果ts.CurrentColumn=pos,则
ts.WordRight(错误)
ts.FindPattern(“>”,vsFindOptions.vsFindOptions规则表达式)
如果结束
ts.Insert(标记,EnvDTE.vsInsertFlags.vsInsertFlagsCollapseToStart)
其他的
ts.MoveToPoint(开始)
如果结束
其他的
ts.MoveToPoint(开始)
如果结束
端接头

如果有HTML重构类型函数,这样你就可以在标记中选择你想要的内容,然后选择所需标记的“wrap with”。实际上我更喜欢像CTRL+向右箭头这样的东西,可以将结束标记向右移动一个字。这样你可以根据需要做很多次…@休:是的,那也很酷。我确实试过这样做,看看它是否有效。很有趣,但我发现当遇到a)时,这种方法失败了。作为行的结尾,当我向右移动一个标记时,它会在br元素中结束,如下所示:
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()
            Dim pos As Integer
            pos = ts.CurrentColumn
            ts.FindPattern(">", vsFindOptions.vsFindOptionsRegularExpression)
            If ts.CurrentColumn = pos Then
                ts.WordRight(False)
                ts.FindPattern(">", vsFindOptions.vsFindOptionsRegularExpression)
            End If
            ts.Insert(tag, EnvDTE.vsInsertFlags.vsInsertFlagsCollapseToStart)
        Else
            ts.MoveToPoint(start)
        End If
    Else
        ts.MoveToPoint(start)
    End If
End Sub