You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pasting after selecting html tag pastes twice #87067
bugIssue identified by VS Code Team member as probable bugeditor-synced-regionIssues related to synced region functionality in editorhtmlHTML support issuesverifiedVerification succeeded
Click after <div (put cursor before the end of opening tag)
Paste some content
=> The pasted content will appear both after <div and after </div. Example with pasting the content class="test" will output <div class="test"></div class="test">
This didn't happen before, it is quite recent bug
Reacted by Simon H, Nate, Stratubas, Josh Siegl, Tom Aalbers, Bryan den Hollander, Jean-Sébastien Goupil, Alexander, aleksandrpnshkn, Adam Morgan and 7 more
This is as-designed, since when you click after <div we creat another cursor. If you type space at this point, we do a special handling to remove the space that would have been inserted at the ending tag. All other actions don't receive this special handling.
You can also turn this off with html.mirrorCursorOnMatchingTag and stick to using F2.
Reacted by Jouke van der Maas, Nate, Tom Aalbers, Jean-Sébastien Goupil, Jeferson Duwe, Arvin Sevilla, Jahrenski, Maximilian Timofeyev, VincentVanWijk and Guilherme Taffarel Bergamin
The described behavior is how it is expected to work. If you disagree, please explain what is expected and what is not in more detail. See also our issue reporting guidelines.
Happy Coding!
Reacted by Jouke van der Maas, Tom Aalbers, Rick Mac Gillis, Jeferson Duwe, Arvin Sevilla, Élio Cró, Maximilian Timofeyev, VincentVanWijk, Simon Siefke, Guilherme Taffarel Bergamin and 1 more
In my opinion there is a bug here. Yes, the feature should create a mirror cursor on a matching tag, but when I'm pasting content with a leading space onto the opening tag, I'd expect the mirroring cursor to handle this like having typed the space manually.
I encounter this a lot because I want to copy some attribute to another tag. On new tags, like
, the closing ">" is right behind the tag name and therefore I include leading spaces when copying, so I can just put the cursor right at the end of the tag and paste. Having to manually press space is an additional step in my workflow and makes this feature rather cumbersome.
Reacted by Simon H, Jouke van der Maas, Stratubas, Tom Aalbers, Jean-Sébastien Goupil, Rick Mac Gillis, aleksandrpnshkn, Arvin Sevilla, Jahrenski, VincentVanWijk and 2 more
Pine (@octref) I'm sorry, but I don't understand how this can possibly be "as-designed"? Shouldn't pasting detect spaces as well?
Also, many times when typing into an HTML tag it does not detect the space. I'll try to figure out if there's something repeatable that causes that issue to happen.
Reacted by Simon H, Jouke van der Maas, Nate, Stratubas, Bryan den Hollander, Tom Aalbers, Aleksandr Hovhannisyan, Jean-Sébastien Goupil, Rick Mac Gillis, aleksandrpnshkn and 6 more
Until this and #90146 (selecting causes selection of things outside the end tag as well) aren't fixed, I'm turning this feature off.
It is a useful feature, but not usable right now. Looks like it wasn't tested in a real world scenario.
also, the end tag will never have more things than the name of the tag itself, therefore pasting shouldn't be part of this feature. At most, when pasting, substitute the end tag with the resulting starting tag after pasting, ignoring the clipboard content.
To your analogy, when I press enter/space/delete on here <div></div|>, VS Code should not do anything, since that always creates syntactically wrong HTML?
We never sell this feature as "magically editing HTML so the result is always semantically correct". What the feature does is just adding another multi-cursor.
What I'll do is add clear UI indication that you are in this mode and your actions will be duplicated. What I won't do is to anticipate any keypress you can press to make HTML semantically invalid and create special-case fixes to prevent that.
Finally this is made an opt-in feature. If you are ok with "Now I see two cursors, what I do will be duplicated, so I should do some action but not others, if I want my action not duplicated I'll ESC to dismiss the extra cursor", then you can turn it on.
Pine (@octref) are you the author of this feature? You have to listen to the community. A project changes based on different usages/requests. With all the bugs around this feature, I would doubt a lot of people will turn this feature on. If you keep saying this is by design, I will also just keep this feature off.
The idea of changing the tag is genial and happens great in VS Razor, but somehow, I end up pressing CTRL+Z way more than I use to and it actually slows me down in my development with visual studio code.
The reason I'm commenting on this issue is because I actually care about the feature, but if you just say this won't happen, then you care more about your code than admitting there might be errors and it should be fixed.
Pasting with two cursors should paste content twice.
Pasting content twice, in this case, creates invalid HTML.
A consistent solution is:
Have two clear mode. One where your action is duplicated. The other not.
User paste in duplicated mode. Content is pasted twice.
User paste in normal mode. Content is not duplicated.
User press an action to enter the duplicated mode.
You can see how it works in Eclipse:
What I'll not do is:
When you press space here, now we emit an additional edit to remove space in the closing div :<div|></div|>
I emit additional edit for paste, enter, delete-after, etc etc to make the HTML valid. That is the magical way that is neither consistent nor understandable. That also makes this feature inapplicable to other languages.
Don't re-invent the wheel here. Razor did it well.
Your "mirror-cursor", is surely a great name, but the real feature (correct me if I'm wrong) is to update the matching HTML tag.
Any other side effects should be handled properly, in respect to get valid HTML (or XML...)
How you handle it under the hood is up to you.
The screenshot you pasted is handled well yes, because it's basically taking into account that in this particular language, space is not part of a variable. But I think this is quite digressing from the main problem. We are not refactoring here. We are just updating a matching HTML tag.
The screenshot you pasted is handled well yes, because it's basically taking into account that in this particular language, space is not part of a variable.
That's not my point. I meant to say:
When your cursor is in that region, paste is duplicated
When your cursor is out, paste is not duplicated
If you dismiss the synced region mode with ESC, paste is not duplicated
Consider this case. Suppose your paste content can either be:
class="foo"
-bar, provided <foo-bar> is a valid tag
Tell me, what should an editor do when pasting in <foo|></foo|>? Isn't <foo class="foo"></foo> and <foo-bar></foo-bar> both valid?
That's why I'm making it explicit when editor is duplicating your changes and not. I never made the promise to say "this feature will always keep your HTML valid".
Pine (@octref) I may be a bit shortsighted, but what exactly this feature brings of new that F2 can't perform? I mean... F2 will change the end tag as well, won't it? Or is this just a WYSIWYG-ish refactoring?
If that's the case, shouldn't F2 be changed to show the changes in real time instead of creating a new feature that tries to do something VSCode already can do?
Pine (@octref) Give it a shot with Razor. I would expect to work like Razor. No magic.
If you paste any without a space, then you duplicate your paste in the closing tag.
If your paste data begins with a space, then you don't duplicate in the closing tag.
If I press space before I paste, then nothing is duplicated in the closing tag.
Apparently this feature is ill advised to make use of multicursors in the first place. It should probably be re-implemented from scratch, this time as "When editing an HTML tag, copy whatever is the first word of the opening tag to the closing tag, no matter what part of and how the opening tag was edited".
Reacted by Sylvain Dumont, Guilherme Taffarel Bergamin and Simon Siefke
In tomorrow's insiders html.mirrorCursorOnMatchingTag is replaced with editor.renameOnType. The new implementation fixes this issue. You can find more details here: #88424 (comment)
bugIssue identified by VS Code Team member as probable bugeditor-synced-regionIssues related to synced region functionality in editorhtmlHTML support issuesverifiedVerification succeeded
Activity
gjsjohnmurray commentedon Dec 16, 2019
Looks like a fault with this new 1.41 feature.
cc Pine (@octref)
octref commentedon Dec 16, 2019
This is as-designed, since when you click after
<divwe creat another cursor. If you type space at this point, we do a special handling to remove the space that would have been inserted at the ending tag. All other actions don't receive this special handling.You can also turn this off with
html.mirrorCursorOnMatchingTagand stick to using F2.vscodebot commentedon Dec 16, 2019
The described behavior is how it is expected to work. If you disagree, please explain what is expected and what is not in more detail. See also our issue reporting guidelines.
Happy Coding!
helgemahrt commentedon Dec 16, 2019
In my opinion there is a bug here. Yes, the feature should create a mirror cursor on a matching tag, but when I'm pasting content with a leading space onto the opening tag, I'd expect the mirroring cursor to handle this like having typed the space manually.
I encounter this a lot because I want to copy some attribute to another tag. On new tags, like
mebibou commentedon Dec 17, 2019
Agreed this new feature should handle pasted content with leading space, just like if you typed it manually. Makes total sense
gavin310 commentedon Dec 17, 2019
Pine (@octref) I'm sorry, but I don't understand how this can possibly be "as-designed"? Shouldn't pasting detect spaces as well?
Also, many times when typing into an HTML tag it does not detect the space. I'll try to figure out if there's something repeatable that causes that issue to happen.
octref commentedon Dec 17, 2019
OK I'll look into how to do this. Meanwhile you can press ESC before pasting for now.
10 remaining items
bergamin commentedon Feb 11, 2020
Until this and #90146 (selecting causes selection of things outside the end tag as well) aren't fixed, I'm turning this feature off.
It is a useful feature, but not usable right now. Looks like it wasn't tested in a real world scenario.
also, the end tag will never have more things than the name of the tag itself, therefore pasting shouldn't be part of this feature. At most, when pasting, substitute the end tag with the resulting starting tag after pasting, ignoring the clipboard content.
octref commentedon Feb 11, 2020
To your analogy, when I press enter/space/delete on here
<div></div|>, VS Code should not do anything, since that always creates syntactically wrong HTML?We never sell this feature as "magically editing HTML so the result is always semantically correct". What the feature does is just adding another multi-cursor.
What I'll do is add clear UI indication that you are in this mode and your actions will be duplicated. What I won't do is to anticipate any keypress you can press to make HTML semantically invalid and create special-case fixes to prevent that.
Finally this is made an opt-in feature. If you are ok with "Now I see two cursors, what I do will be duplicated, so I should do some action but not others, if I want my action not duplicated I'll ESC to dismiss the extra cursor", then you can turn it on.
jsgoupil commentedon Feb 11, 2020
Pine (@octref) are you the author of this feature? You have to listen to the community. A project changes based on different usages/requests. With all the bugs around this feature, I would doubt a lot of people will turn this feature on. If you keep saying this is by design, I will also just keep this feature off.
The idea of changing the tag is genial and happens great in VS Razor, but somehow, I end up pressing CTRL+Z way more than I use to and it actually slows me down in my development with visual studio code.
The reason I'm commenting on this issue is because I actually care about the feature, but if you just say this won't happen, then you care more about your code than admitting there might be errors and it should be fixed.
octref commentedon Feb 11, 2020
Jean-Sébastien Goupil (@jsgoupil) I'm saying it should happen in a consistent way, not a magical way. Your issue is #87732, which I plan to fix with #88424.
The dilemma is:
A consistent solution is:
You can see how it works in Eclipse:

What I'll not do is:
<div|></div|>jsgoupil commentedon Feb 11, 2020
Don't re-invent the wheel here. Razor did it well.
Your "mirror-cursor", is surely a great name, but the real feature (correct me if I'm wrong) is to update the matching HTML tag.
Any other side effects should be handled properly, in respect to get valid HTML (or XML...)
How you handle it under the hood is up to you.
The screenshot you pasted is handled well yes, because it's basically taking into account that in this particular language, space is not part of a variable. But I think this is quite digressing from the main problem. We are not refactoring here. We are just updating a matching HTML tag.
octref commentedon Feb 11, 2020
That's not my point. I meant to say:
Consider this case. Suppose your paste content can either be:
class="foo"-bar, provided<foo-bar>is a valid tagTell me, what should an editor do when pasting in
<foo|></foo|>? Isn't<foo class="foo"></foo>and<foo-bar></foo-bar>both valid?That's why I'm making it explicit when editor is duplicating your changes and not. I never made the promise to say "this feature will always keep your HTML valid".
bergamin commentedon Feb 11, 2020
Pine (@octref) I may be a bit shortsighted, but what exactly this feature brings of new that F2 can't perform? I mean... F2 will change the end tag as well, won't it? Or is this just a WYSIWYG-ish refactoring?
If that's the case, shouldn't F2 be changed to show the changes in real time instead of creating a new feature that tries to do something VSCode already can do?
jsgoupil commentedon Feb 11, 2020
Pine (@octref) Give it a shot with Razor. I would expect to work like Razor. No magic.
If you paste any without a space, then you duplicate your paste in the closing tag.
If your paste data begins with a space, then you don't duplicate in the closing tag.
If I press space before I paste, then nothing is duplicated in the closing tag.
LWChris commentedon Feb 12, 2020
Apparently this feature is ill advised to make use of multicursors in the first place. It should probably be re-implemented from scratch, this time as "When editing an HTML tag, copy whatever is the first word of the opening tag to the closing tag, no matter what part of and how the opening tag was edited".
octref commentedon Mar 18, 2020
In tomorrow's insiders
html.mirrorCursorOnMatchingTagis replaced witheditor.renameOnType. The new implementation fixes this issue. You can find more details here: #88424 (comment)