Improve TSV serialization for tab and newline characters in cell value when copying cells to the clipboard #2811
Labels
ready
Ready for implementation
restricted: maintainers
Only maintainers can resolve this issue
type: enhancement
New feature or request
work: frontend
Related to frontend code in the mathesar_ui directory
Milestone
Current behavior
You can copy the selected cells in a sheet via Ctrl+C (Cmd+C on Mac OS).
Mathesar writes one string to the clipboard, a TSV representation of the cells.
The TSV serialization logic is very simplistic. Columns are separated by tab characters. Rows are separated by newline characters.
If a cell value contains a tab or newline character, the TSV serialization will not accurately represent the cell values.
You can test this out by setting a cell value to some text which contains a newline. Either use Ctrl+Enter to manually enter a newline, or paste some text into the cell which contains a newline. When rendering the cell in select mode, the newline won't display. It will show again when you enter edit mode on the cell though.
Here I have four cells, and I have newlines entered between "apple" and "banana" and also between "broccoli" and "carrot"
Copying the cells gives this text:
If you paste that text into another spreadsheet application, you'll get six cells instead of four. That's not good
Desired behavior
Our Clipboard Interaction specs has a TSV section with more details about how the serialization logic should work.
In the above example, copying those four cells should give this text:
The double quotes ensure that the newlines are parsed as cell content rather than row delimiters.
Implementation
The text was updated successfully, but these errors were encountered: