vscode-auto-rename-tag icon indicating copy to clipboard operation
vscode-auto-rename-tag copied to clipboard

Does not handle multi-line starting tags

Open kylpo opened this issue 8 years ago • 11 comments

Given code like:

<View
  prop1="1"
>
  <Button />
</View>

Renaming <View will not rename </View>

However, it will be correctly renamed with code like:

<View prop1="1">
  <Button />
</View>

Thanks for this extension! Seems like an idea subtle and good enough to become standard in future editors. I look forward to using it!

kylpo avatar Jan 23 '17 04:01 kylpo

Currently, this extension does not handle multi-line tags, since it may produce unexpected renaming tag if we do not handle well. I will investigate if it is possible to handle that well.

formulahendry avatar Jan 23 '17 11:01 formulahendry

Got it - thanks. Really appreciate your work on this!

kylpo avatar Jan 23 '17 15:01 kylpo

this is especially important with html templating such as angular templates where we have a lot of attributes/directives on most elements. Great extension but only works half the time because of this limitation.

yerol avatar Jan 25 '17 10:01 yerol

Any progress on this? I love the idea of this plugin, but since I work in React where many of my tags are multiline, using it actually puts me into a false sense of security because I forget to change the closing tags every single time I edit a multiline tag.

jessejanderson avatar Sep 26 '17 16:09 jessejanderson

I would suggest an experimental feature that enable multi-line support first.

Adding the following regex to the original start tag regex should solve most of the problem: (?:^\s*(?:<!--\s*)?<(\w)+| ....... )

99% of the time multi-line tag would be the first of the line. It is very unlikely, and probably shouldn't be, that a line is start with < but not a tag. Finding closing bracket is not necessary in this case. It also avoid dueling with attributes that contains <> .

One potential trouble is from comments, but any mess can be written in comments anyway.

Not pretty, but it should cover most of the use case. I believe most users would gladly take the trade.

sirius0xff avatar Apr 24 '18 06:04 sirius0xff

actually this is related to a hamful bug - if you have a multiline div inside another div, and rename the outer div, the matching is wrong, and the inner closing is renamed, causing your document structure to break.

example: renaming the first div, causes the closing tag of the <div class="article-text" to be renamed

      <div *ngIf="!submitted_backend">
        <header>
          <h1 class="article-title h2">{{ context.title }}</h1>
          <h5>{{ context.description }}</h5>
        </header>

        <div class="article-text"
             *ngIf="text"
             [innerHTML]="text | transformlinks | safehtml">
        </div>

        <sf-form [schema]="schema"
                 [model]="model"
                 [actions]="actions"
                 [validators]="validators"></sf-form>

        <div *ngIf="formError"
             class="alert alert-danger submit-alert">Fejlene ovenfor skal rettes før formularen kan sendes ind.
        </div>

      </div>

sunew avatar Jun 15 '18 19:06 sunew

@sunew I've been unable to use this plugin because of this. 😞

I keep an eye on hoping for a fix because I love the plugin, but the projects I work on have a lot of nested multiline divs which causes this to break often.

jessejanderson avatar Jun 19 '18 16:06 jessejanderson

Same here - this is quite the bummer

olee avatar Feb 07 '19 11:02 olee

👀

giancarlosisasi avatar Apr 19 '19 21:04 giancarlosisasi

This is also the case for me. This is an excellent plugin and I absolutely love it, but I can't use it because of this issue.

devnoel avatar Aug 27 '19 08:08 devnoel

I would suggest an experimental feature that enable multi-line support first.

Adding the following regex to the original start tag regex should solve most of the problem: (?:^\s*(?:<!--\s*)?<(\w)+| ....... )

99% of the time multi-line tag would be the first of the line. It is very unlikely, and probably shouldn't be, that a line is start with < but not a tag. Finding closing bracket is not necessary in this case. It also avoid dueling with attributes that contains <> .

One potential trouble is from comments, but any mess can be written in comments anyway.

Not pretty, but it should cover most of the use case. I believe most users would gladly take the trade.

@sirius0xff you don't happen to have a fork with this change?

scriptcoded avatar Sep 16 '19 14:09 scriptcoded