feat(datagrid): copy column values plus Copy as CSV/Markdown/IN Clause (#1325)#1330
Merged
Merged
Conversation
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
Closes #1325 (能否添加复制多条id功能? — "Can you add a feature to copy multiple IDs, or copy an entire column?").
Adds two complementary entry points to the data grid:
(1, 2, 3)or('a', 'b')from the right-clicked column across the selected rows, ready to paste into aWHERE col IN (...)query.Native macOS pattern throughout — NSMenu / NSMenuItem with
representedObjectcarrying column indices, dispatching to coordinator methods that mirror the existingcopyRowsAsJson(at:)/copyRowsAsInsert(at:)shape. No new abstractions; new converters (CsvRowConverter,MarkdownTableConverter,InClauseConverter) live inCore/Utilities/SQL/alongside the existingJsonRowConverter/SQLRowToStatementConverterand follow the same struct shape.ClipboardServicegains awriteCsv(_:)method that writes.string+utf8PlainText+public.comma-separated-values-textso pasting CSV into Numbers/Excel works without content-sniffing.writeTextandwriteRowsare unchanged.Design decisions
NULLliteral (matches grid display). IN Clause: NULLs are filtered out —WHERE x IN (.., NULL, ..)never matches NULL rows in three-valued SQL logic anyway, so emitting them would silently mislead the user.Cmd+C(TSV) andCmd+Shift+C(TSV with Headers) stay default.Cmd+Opt+Cis reserved by macOS for "Copy Style" in text contexts and would conflict in the SQL editor.Code centralization
Following the existing
copyRowsAsJson(at:)pattern exactly:All three converters use the driver-provided
escapeStringLiteralclosure when the column needs SQL quoting — same pattern asSQLRowToStatementConverter.Files changed
CsvRowConverter.swift,MarkdownTableConverter.swift,InClauseConverter.swiftCsvRowConverterTests,MarkdownTableConverterTests,InClauseConverterTests(24 tests, all passing)ClipboardService.swift— newwriteCsv(_:)plus protocol method; existing mocks updatedDataGridRowView.swift— 4 new menu items + actions, dedup helperselectedOrCurrentIndices(in:)covering 8 existing call sites that had the same guard/ternary pattern duplicatedDataGridView+Sort.swift— 1 new header-menu item + actionLocalizable.xcstrings— Xcode auto-extracted new String(localized:) keysdocs/features/data-grid.mdx— full Copy as / Copy Column Values table, plus a correction (Cmd+Shift+C was documented as "CSV"; it's actually TSV with Headers)Verification
RowOperationsManagerCopyTests+CellPasteRoutingTestsstill greenTest plan
id INTcolumn, right-click on theidcell, Copy as → IN Clause — clipboard contains(1, 2, 3).name VARCHARcolumn — clipboard contains('a', 'b', 'c')with proper quoting.O'Brienanddoe, john— RFC 4180 compliant quoting.Cmd+C(TSV) andCmd+Shift+C(TSV with Headers) behavior unchanged.