Skip to content

Pasting after selecting html tag pastes twice #87067

Closed

Description

@mebibou
  • VSCode Version: 1.41.0
  • OS Version: MacOS 10.15.1

Steps to Reproduce:

  1. Write the html code <div></div>
  2. Click after <div (put cursor before the end of opening tag)
  3. 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

Activity

  1. gjsjohnmurray commented on Dec 16, 2019

    @gjsjohnmurray
    Contributor

    Looks like a fault with this new 1.41 feature.

    cc Pine (@octref)

  2. octref commented on Dec 16, 2019

    @octref
    Contributor

    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.

  3. added
    *as-designed
    on Dec 16, 2019
  4. vscodebot commented on Dec 16, 2019

    @vscodebot

    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!

  5. helgemahrt commented on Dec 16, 2019

    @helgemahrt

    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.

  6. mebibou commented on Dec 17, 2019

    @mebibou
    Author

    Agreed this new feature should handle pasted content with leading space, just like if you typed it manually. Makes total sense

  7. gavin310 commented on Dec 17, 2019

    @gavin310

    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.

    vscode-bug

  8. octref commented on Dec 17, 2019

    @octref
    Contributor

    OK I'll look into how to do this. Meanwhile you can press ESC before pasting for now.

  9. added
    bug
    and removed
    *as-designed
    on Dec 17, 2019
  10. 10 remaining items

  11. bergamin commented on Feb 11, 2020

    @bergamin

    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.

  12. octref commented on Feb 11, 2020

    @octref
    Contributor

    since it is always syntactically wrong.

    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.

  13. jsgoupil commented on Feb 11, 2020

    @jsgoupil

    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.

  14. octref commented on Feb 11, 2020

    @octref
    Contributor

    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:

    • 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:
    Kapture 2020-02-11 at 11 05 26

    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.
  15. jsgoupil commented on Feb 11, 2020

    @jsgoupil

    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.

  16. octref commented on Feb 11, 2020

    @octref
    Contributor

    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".

  17. bergamin commented on Feb 11, 2020

    @bergamin

    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?

  18. jsgoupil commented on Feb 11, 2020

    @jsgoupil

    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.

  19. LWChris commented on Feb 12, 2020

    @LWChris

    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".

  20. octref commented on Mar 18, 2020

    @octref
    Contributor

    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)

  21. locked and limited conversation to collaborators on May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugeditor-synced-regionhtmlverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions