Steps to Reproduce:
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
@bfelbo VS Code writes to the clipboard two distinct contents:
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?
@bfelbo Have you tried disabling all extensions?
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: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
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
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
Thank you for following through. I think this is a bug specific to Postico, where they read the HTML value in the clipboard.
@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
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@alexandrudima can we open this issue again?
A short follow up on this issue:
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.
@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...
Verification steps:
a.ts in VS Code with the content class C { } (be sure to have it colored)b.tsCompare a.ts and b.ts using a binary viewer:
a.ts - spaces are 0x20 - Unicode Character 'SPACE' (U+0020):
b.ts - spaces are 0xC2 0xA0 - Unicode Character 'NO-BREAK SPACE' (U+00A0):
fyi @rebornix
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: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
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
@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.
Most helpful comment
@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
NSTextFieldconfigured 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
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