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

Improve TSV serialization for tab and newline characters in cell value when copying cells to the clipboard #2811

Closed
seancolsen opened this issue Apr 12, 2023 · 1 comment · Fixed by #2867
Assignees
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

Comments

@seancolsen
Copy link
Contributor

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"

    image

    Copying the cells gives this text:

    apple
    banana	cherry
    asparagus	broccoli
    carrot
    

    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:

    "apple
    banana"	cherry
    asparagus	"broccoli
    carrot"
    

    The double quotes ensure that the newlines are parsed as cell content rather than row delimiters.

Implementation

  • We also need to deserialize the TSV string during paste, and that logic is more complex. As such, we should see if we can find a 3rd party library to handle the serialization and deserialization for us.
@seancolsen seancolsen added ready Ready for implementation type: enhancement New feature or request work: frontend Related to frontend code in the mathesar_ui directory restricted: maintainers Only maintainers can resolve this issue labels Apr 12, 2023
@seancolsen seancolsen added this to the Backlog milestone Apr 12, 2023
@seancolsen seancolsen self-assigned this Apr 18, 2023
@seancolsen
Copy link
Contributor Author

Note: we also need to properly handle commas and quotes in cell contents too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant