node-copy-paste
node-copy-paste copied to clipboard
[Windows] using UTF-8 and unicode code page on copy
Resolves #40
The problem
- We have been encoding data to copy as UTF-16LE, which should be fine!
- Unfortunately Windows (specifically clip.exe) appears to use the dreaded
isTextUnicode
to decide character encoding. - This means that sometimes extended chars copy correctly, other times not. (Demonstrated in test cases in notatestuser/node-copy-paste@f8b93be on Windows)
What this PR changes
- Use a .bat to spawn clip.exe
- Change the active code page to 65001
- Pipe UTF-8 to clip.exe
- Change the code page back once done
This way isTextUnicode
is more likely to give us its blessing.
Things I tried
- Adding a BOM (works, but BOM is also copied to clipboard as extra data)
- Using a file encoded as UTF-16LE (results in the same BOM issue; BOM-less files must be UTF-8, which yield mixed results)
- VB script with base64 for copying (slow, hacky)
I would like to see #40 resolved soon...
So I've resolved this in my fork as the maintainer of this package hasn't merged my PR. It's published on npm as copy-paste-win32fix.
I hope that helps you!