Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy pasting from latest VS Code adds invisible characters #80825

Closed
bfelbo opened this issue Sep 12, 2019 · 13 comments
Closed

Copy pasting from latest VS Code adds invisible characters #80825

bfelbo opened this issue Sep 12, 2019 · 13 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-clipboard Editor clipboard issues macos Issues with VS Code on MAC/OS X verified Verification succeeded
Milestone

Comments

@bfelbo
Copy link

bfelbo commented Sep 12, 2019

  • VSCode Version: 1.38.1 (downgraded to 1.34 and it works as intended)
  • OS Version: macOS Mojave 10.14.1 (18B75)

Steps to Reproduce:

  1. Copy paste code from VS Code into another editor. In my case, I copy SQL code into the editor Postico.
  2. Functionality in other editors and code bases will break due to the invisible characters.
  3. Enable extensions and copy back the code from the other editor. Now extensions like these (https://marketplace.visualstudio.com/items?itemName=wengerk.highlight-bad-chars, https://marketplace.visualstudio.com/items?itemName=nachocab.highlight-dodgy-characters) will show all spaces as being bad characters.

I reproduced these steps, but copying from Atom instead of VS Code, and everything worked fine. Similarly, everything works fine in an older version of VS Code (1.34).

Does this issue occur when all extensions are disabled? Yes

@alexdima alexdima added the macos Issues with VS Code on MAC/OS X label Sep 13, 2019
@alexdima
Copy link
Member

@bfelbo VS Code writes to the clipboard two distinct contents:

  • a plain text content
  • an HTML content

An application, when pasting to it, can choose which content type to read from the clipboard. A code editor typically reads the plain text content. That is what VS Code does when you paste into it. A rich editor (like Word) typically reads the HTML content.

I think the Postico editor might have an issue where it reads the HTML content from clipboard. How do things look like when you copy from VS Code and paste to another VS Code window?

@alexdima alexdima added the info-needed Issue requires more information from poster label Sep 13, 2019
@alexdima
Copy link
Member

@bfelbo Have you tried disabling all extensions?

@vscodebot vscodebot bot removed the new release label Sep 16, 2019
@ilTofa
Copy link

ilTofa commented Sep 17, 2019

I had the same problem of pasting code from Code behaving strangely in other programs. I was able to track back that in the pasted clipboard spaces in code are substituted by the sequence c2a0 (that's utf-8 for the non-breaking space character).

This breaks some program, while others seems to convert to spaces (textmate).

To reproduce: copy some code from Visual Studio Code; paste it in Postico (I had the same problem with other editors, may be Xcode itself, but this is what I'm using now); copy from Postico; paste in a file (or in textmate); read the file with an hex-editor to find the nbsp characters.

This could be a bug in Postico (as you said above) but I just tried to copy html from safari and paste it in Postico and no nbsp appeared.

Hope this helps you narrow down the problem. I'm on latest stable macOS. Code in itself reports:
Versione: 1.38.1
Commit: b37e54c
Data: 2019-09-11T13:31:32.854Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 18.7.0

@ilTofa
Copy link

ilTofa commented Sep 18, 2019

For the records, this is considered a bug in Postico. There is a workaround in the issue lined above, that's using a VSCode extension that does a copy without formatting: https://marketplace.visualstudio.com/items?itemName=bmaupin.copy-without-formatting

@alexdima
Copy link
Member

alexdima commented Sep 18, 2019

Thank you for following through. I think this is a bug specific to Postico, where they read the HTML value in the clipboard.

@jakob
Copy link

jakob commented Sep 18, 2019

@alexandrudima

Postico developer here.

This issue is not unique to Postico. It also happens with Text Edit. It also happens with Mail. If people copy-paste text from VS Code to Mail, they'll end up with the wrong type of spaces.

It happens with every app that uses a standard Cocoa NSTextField configured for rich text.

In Postico I found a workaround. If I change the text field type to richText = NO, then pasting works correctly. Since VS Code is popular we'll probably do that, but it's a less than perfect workaround, since it changes a few other behaviors, which we'll have to find some additional workarounds for. It's also not going to fix this problem for all the other Mac apps out there.

Anyway, the problem is that AppKit prefers HTML to plain text when pasting into a rich text field. I think that Apple's assumption was that plain text and styled text would be identical except for attributes.

In my opinion VS Code should do one of the following things

  • only copy plain text to the pasteboard
  • copy NSAttributedString to the pasteboard instead of HTML
  • use something like white-space: pre; to control white space display in HTML instead of using non-breaking spaces, so that when other apps use the HTML version they get the same characters

@NinoFloris
Copy link

@alexandrudima can we open this issue again?

@jakob
Copy link

jakob commented Oct 1, 2019

A short follow up on this issue:

  • we've just released an update to Postico that works around the issue. The problem should no longer happen with Postico 1.5.9
  • this is still an issue for many other Mac apps. For example, Text Edit and Mail are still affected.

So if you copy text from VS Code to Mail, you'll end up with the wrong spaces.

I still think the VS code developers should fix this.

@alexdima alexdima reopened this Oct 2, 2019
@alexdima
Copy link
Member

alexdima commented Oct 2, 2019

@jakob Thank you for the nice write-up. I agree, we should improve what we write to the html clipboard such that the text content of those dom nodes still represents the source text...

I think I personally always considered the HTML clipboard as a "painting canvas", i.e. it doesn't matter what kind of spaces we'd write in there given that code would most likely be pasted in a rich email or a rich document and be used for "viewing" only... But the text could then be further copied out from the email/rich document and pasted back into another editor...

@alexdima alexdima removed the info-needed Issue requires more information from poster label Oct 2, 2019
@alexdima alexdima modified the milestones: September 2019, October 2019 Oct 2, 2019
@alexdima
Copy link
Member

Verification steps:

  1. create a file a.ts in VS Code with the content class C { } (be sure to have it colored)
  2. select all and copy in VS Code
  3. paste to a new document in TextEdit (the text will appear colored)
  4. select all and copy in TextEdit
  5. paste to a new document in VS Code which you can save as b.ts

Compare a.ts and b.ts using a binary viewer:

  • a.ts - spaces are 0x20 - Unicode Character 'SPACE' (U+0020):
    image
  • b.ts - spaces are 0xC2 0xA0 - Unicode Character 'NO-BREAK SPACE' (U+00A0):
    image

@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Oct 10, 2019
@alexdima
Copy link
Member

fyi @rebornix

@alexdima alexdima added the editor-clipboard Editor clipboard issues label Oct 10, 2019
@asverq
Copy link

asverq commented Oct 19, 2019

I have a problem like that, but i am have an aditional case, when i am copying from vs-code to wordpress editor in browser this code:
[iframe href="http://wp-kama.ru" height="600px" width="400px"]

i am having output like that:
[iframe href=»http://wp-kama.ru» height=»600px» width=»400px»]

VS-Code:
Version: 1.39.2 (user setup)
Commit: 6ab5985
Date: 2019-10-15T15:35:18.241Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

@alexdima
Copy link
Member

@asverq Your issue is IMHO not related to the original issue.

It appears that in your case, when you paste in wordpress, the text is changed and all the " Quotation Mark characters are replaced with » Right-Pointing Double Angle Quotation Mark

AFAIK we have no such replacement implemented in our code base, so I would think it is an issue with wordpress. If you consider this to be an issue with VS Code, please open a new issue.

@weinand weinand added the verified Verification succeeded label Oct 30, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-clipboard Editor clipboard issues macos Issues with VS Code on MAC/OS X verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants