Skip to content

fix(datagrid): keep pasted rows aligned when a cell value contains a comma#1436

Merged
datlechin merged 1 commit into
mainfrom
fix/paste-rows-structured-clipboard
May 27, 2026
Merged

fix(datagrid): keep pasted rows aligned when a cell value contains a comma#1436
datlechin merged 1 commit into
mainfrom
fix/paste-rows-structured-clipboard

Conversation

@datlechin
Copy link
Copy Markdown
Member

Problem

Copy a grid row with Cmd+Shift+C, paste it back, and the values land in the wrong columns when a cell contains a comma. Reported with a last_user_agent value:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36

Pasting produced:

INSERT INTO `access_tokens` (`token`, `user_id`, ...) VALUES ('like Gecko) Chrome/148.0.0.0 Safari/537.36', NULL, NULL, NULL, NULL, NULL, NULL, NULL);

Root cause

Cmd+Shift+C copies the row as TSV, but the paste path (RowOperationsManager.pasteRowsFromClipboard) ignored the typed pasteboard data and re-guessed the format from plain text. detectParser tallied lines containing a tab vs a comma; a single row whose value holds a comma scored tabLines == commaLines == 1, the tabCount > commaCount tie failed, and it fell back to the CSV parser. CSV ignores the tab separators and split the row on the first comma inside (KHTML, like Gecko), so one fragment landed in token and the rest became NULL.

The copy path already labels the clipboard with a private com.TablePro.gridRows type, but it only carried the flag "1" and the paste path never read it.

Fix

Use the NSPasteboard representations the copy already produces instead of guessing:

  • com.TablePro.gridRows now carries the JSON-encoded [[PluginCellValue]]. Paste decodes it first, so internal copy/paste is lossless: commas, embedded tabs/newlines, a real NULL vs the literal string "NULL", and binary all round-trip.
  • detectParser rewritten for the genuine plain-text fallback (spreadsheets, the SQL editor, other apps): a tab anywhere means TSV (tab is the native tabular-clipboard delimiter for TablePro, Excel, and Numbers); CSV only when commas appear without tabs. This alone fixes external TSV-with-commas.
  • The two grid copy paths attach the raw cell values as the structured payload; the formatted TSV still goes to external apps.

The writeRows signature change and both test mocks are in the same commit.

Tests

  • Pasteboard round-trip of structured rows including a comma value, a literal "NULL", and binary (ClipboardServiceTests).
  • The reported comma regression, real-NULL-vs-"NULL" distinction, structured-wins-over-text, and detectParser cases (RowOperationsManagerPasteTests).

Notes

No new user-facing strings, shortcuts, or settings, so no docs change. docs/features/keyboard-shortcuts.mdx already documents "Paste TSV as new rows"; this makes it hold for values containing commas.

@datlechin datlechin force-pushed the fix/paste-rows-structured-clipboard branch from 93165f6 to 01ae0ae Compare May 27, 2026 11:59
@datlechin datlechin force-pushed the fix/paste-rows-structured-clipboard branch from 01ae0ae to 57fc132 Compare May 27, 2026 12:07
@datlechin datlechin merged commit f31d975 into main May 27, 2026
1 of 2 checks passed
@datlechin datlechin deleted the fix/paste-rows-structured-clipboard branch May 27, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant