fix(datagrid): route Cmd+V to row paste when clipboard holds copied rows#935
Merged
fix(datagrid): route Cmd+V to row paste when clipboard holds copied rows#935
Conversation
Cmd+C on a row selection writes TSV via ClipboardService and Cmd+V then routed through pasteCellsFromClipboard, which overwrote cells starting at the focused cell with the source row's values, instead of inserting a new row. The asymmetry was: Cmd+C always operated on selectedRowIndexes (row level), Cmd+V chose cell paste whenever any cell was focused, so copying then pasting in the same selection looked like the row's tail columns silently mutated. Two signals now defer cell paste to dataGridPasteRows (which inserts): 1. The clipboard was written by this app's row-copy path. ClipboardProvider gains a writeRows(tsv:html:?) method that tags the pasteboard with com.TablePro.gridRows. pasteCellsFromClipboard checks hasGridRows first and bails when set. 2. The clipboard's TSV shape is full-row (every line has exactly numberOfDataColumns values). Catches external row-shaped data the user clearly intended as a row insert. Migrates RowOperationsManager.copySelectedRowsToClipboard and TableViewCoordinator.copyRows / copyRowsWithHeaders from writeText / writeTabular to writeRows. Drops the now-unused writeTabular method from the protocol. Cell paste continues to work for external single-column or shape-mismatched TSV (clearly cell-shaped data from spreadsheets etc.). Right-click row > Paste and Cmd+V with no cell focus already went straight to row paste; unchanged.
Locks the contract that pasteCellsFromClipboard returns false (deferring to dataGridPasteRows) on the two new signals: clipboard carries the gridRows tag, or every TSV line matches the table's column count. Without these tests, the bug from this same PR could regress silently if someone changes the pasteboard tag string or removes the shape check. Also covers the cell-paste happy path (shape-mismatched TSV) and the read-only short-circuit.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35c89c8fe5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a Cmd+C / Cmd+V asymmetry: Cmd+C copies the selected rows (row-level), but Cmd+V was always cell-pasting whenever a cell had focus — so copying a row then pasting silently overwrote the row's tail columns with the source row's leading values instead of inserting a new row.
Root cause
KeyHandlingTableView.paste(_:)chose between cell paste and row paste based purely on whether a cell was focused:Clicking any cell sets focus, but
copy(_:)always usesselectedRowIndexes. Net effect: copy works at row level, paste at cell level, and the round trip mangles cells.Fix
pasteCellsFromClipboardnow defers to row paste on two signals:ClipboardProvidergainswriteRows(tsv:html:?)which writes the TSV (and optional HTML) plus acom.TablePro.gridRowspasteboard type.hasGridRowsreads it. MigratesRowOperationsManager.copySelectedRowsToClipboardandTableViewCoordinator.copyRows/copyRowsWithHeadersto use it. Drops the now-unusedwriteTabular.numberOfDataColumnsvalues, treat it as full rows. Catches external row-shaped data (e.g., from another DB tool) that the user clearly meant as an insert.Cell paste continues to work for shape-mismatched TSV (external spreadsheet selections, single-column copies, etc.).
Audit of other paste paths (no changes needed)
TableRowViewWithMenuright-click row > Paste → already callsdataGridPasteRowsdirectlyMainContentCommandActions.pasteRows(menu /.pasteRowsnotification) → already callscoordinator?.pasteRows()directlyOnly the Cmd+V keyboard path needed routing fix.
Test plan
RowOperationsManagerCopyTestspass (mock updated to new protocol)