vscode_rainbow_csv icon indicating copy to clipboard operation
vscode_rainbow_csv copied to clipboard

escape value on paste

Open mfulton26 opened this issue 11 months ago • 5 comments

I occassionally get "double quote chars are not consistent" formatting error. Can this plugin add support for auto-escaping quotes when pasting text into a CSV file? If that is out of scope for this extension then are there any that can be recommended? I haven't found one yet.

mfulton26 avatar Jan 22 '25 16:01 mfulton26

I am unaware of any extension that would do this, but it sounds like an interesting feature! Can you please add an example of an unescaped text fragment and then how would the escaped version look like?

mechatroner avatar Jan 23 '25 03:01 mechatroner

Yes. Thank you.

Initial CSV file contents:

id,story
1,"Geolocation ""foreground"" support"

Edit scenarios:

  1. Paste 2,Geolocation "background" support.
  2. Type 2, manually and then paste Geolocation "background" support.

Current result:

id,story
1,"Geolocation ""foreground"" support"
2,Geolocation "background" support

Desired result:

id,story
1,"Geolocation ""foreground"" support"
2,"Geolocation ""background"" support"

mfulton26 avatar Jan 23 '25 13:01 mfulton26

An alternative solution might be to detect whenever pasting inside existing quotation marks and then escape any quotation marks inside the text being pasted.

mfulton26 avatar Feb 10 '25 15:02 mfulton26

IMO this is doable there is already a concept of "simple" dialect that doesn't treat double quotes in any special way. So the logic could be to try to parse the fragment as standard csv, if this fails try to parse as "simple" - if this succeeds - reencode and replace the new fragment with standard dialect with escaped double quotes. There is also a question of how intrusive this replacement would be, probably needs some sort of dialog to confirm such automatic alteration of the copied data.

mechatroner avatar Feb 11 '25 05:02 mechatroner

I got confused for a moment and though VS Code had some built-in support for CSV. 🤪

However, when I created a feature request there I did have some more clarity on how I think this should perhaps work and I outlined three simple scenarios (https://github.com/microsoft/vscode/issues/262971):

here's one scenario:

Given `this is "cool"` on my clipboard
When I paste it into an empty CSV field
Then the inserted text is `"this is ""cool"""`

here's another scenario:

Given `this is "cool"` on my clipboard
When I paste it into a non-empty CSV field that is already double-quoted
Then the inserted text is `this is ""cool""`

one more scenario:

Given `this is "cool"` on my clipboard
When I paste it into a non-empty CSV field that is NOT already double-quoted
Then the inserted text is `this is ""cool""` and the field value is wrapped in double-quotes

mfulton26 avatar Aug 22 '25 19:08 mfulton26