feat(datagrid): paste cells from clipboard (Cmd/Ctrl+V) - #612
Open
ymadd wants to merge 2 commits into
Open
Conversation
handlePendingChange / handlePendingInsertionChange computed the next pending state from a tabsRef snapshot taken before the update. When many cells are staged in the same tick (e.g. a multi-cell clipboard paste), every call reads the same stale snapshot and React batches the setState calls, so only the last cell's change survives. updateTab now also accepts an updater function ((tab) => partial) and both handlers compute the next pending state inside it, so rapid successive updates compose instead of clobbering each other.
Copying cells has been supported for a while, but there was no way to paste back into the grid. This adds spreadsheet-style paste as staged edits (pending changes), applied via the existing commit/rollback flow: - Cmd/Ctrl+V pastes at the selection: the cell range's top-left, the top of the row selection, or the focused cell. A context-menu Paste entry pastes at the right-clicked cell. - Tab-separated cells win (spreadsheet convention). Multi-line text without tabs is parsed as CSV with double-quote escaping, preferring the configured CSV delimiter, so the grid's own copy formats (comma/semicolon/pipe) round-trip. A single line without tabs is always one value, so free text like "hello, world" lands in one cell. - A leading header row is dropped when every cell matches a column name (round-trip of the "export column names" option). - A single copied value fills the whole selected range / selected rows. - The paste matrix is clipped at the grid edges; existing rows require an identifiable key (insertion rows accept a paste regardless). - Pasting a cell's original value back clears its pending change, same as inline editing.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (18 files)
Reviewed by step-3.7-flash · Input: 194.2K · Output: 30.3K · Cached: 2.4M |
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.
Closes #611
Summary
The data grid supports copying cells/rows/ranges but not pasting. This PR adds spreadsheet-style paste as staged edits — pasted values go through the existing pending-changes flow (apply/rollback), never directly to the database.
Behavior
hello, worldlands in one cell.Prerequisite fix (first commit)
handlePendingChange/handlePendingInsertionChangecomputed the next pending state from atabsRefsnapshot; with N staged cells in one tick, React batches the updates and only the last cell survived.updateTabnow also accepts an updater function and both handlers compute inside it. Multi-cell paste is the first caller that hits this, but it hardens every rapid-succession staging path.Known limitations
rowToCSV), so values containing the delimiter don't survive a copy→paste round-trip. Robust CSV serialization is follow-up material.NULLcopies as the literal stringnull, so pasting it into another cell stages that string, not SQL NULL.Testing
tests/utils/dataGrid.test.ts: 23 new cases forparsePasteMatrix/stripHeaderRow/computePasteTargets(TSV/CSV/quotes/delimiter detection/positional header stripping/range fill/clipping).tsc --noEmit,eslint, and the vitest suite are green (the 3 failing files onmain— ThemeProvider/SettingsProvider/useSidebarResize — fail identically without this change).i18n
3 new keys (
pasteCells,pastedCells,pasteNotEditable) added to all 11 locales.