Skip to content

Commit ac29ba8

Browse files
committed
fix(datagrid): copy the rectangular grid selection from the context menu like Cmd+C
1 parent 15d0198 commit ac29ba8

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

TablePro/Views/Results/DataGridRowView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ class DataGridRowView: NSTableRowView {
419419

420420
@objc private func copyFromContextMenu(_ sender: NSMenuItem) {
421421
guard let coordinator else { return }
422+
if !coordinator.selectionController.isEmpty {
423+
coordinator.copyGridSelection(coordinator.selectionController.selection)
424+
return
425+
}
422426
switch sender.representedObject as? CopyContextTarget {
423427
case .cell(let columnIndex):
424428
coordinator.copyCellValue(at: rowIndex, columnIndex: columnIndex)

TableProTests/Views/Results/DataGridRowViewCopyTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,25 @@ struct DataGridRowViewCopyTests {
184184

185185
#expect(delegate.copiedRows == Set([0, 1]))
186186
}
187+
188+
@Test("Copy uses the rectangular grid selection when one exists")
189+
func copyUsesGridSelection() {
190+
let clipboard = DataGridRowViewCopyClipboard()
191+
ClipboardService.shared = clipboard
192+
defer { ClipboardService.shared = NSPasteboardClipboardProvider() }
193+
194+
let coordinator = makeCoordinator(
195+
rows: [[.text("1"), .text("Alice")], [.text("2"), .text("Bob")]],
196+
columnTypes: [.integer(rawType: "INT"), .text(rawType: "TEXT")]
197+
)
198+
coordinator.selectionController.selectAll(totalRows: 2, totalColumns: 2)
199+
200+
let rowView = DataGridRowView()
201+
rowView.coordinator = coordinator
202+
rowView.rowIndex = 0
203+
204+
invokeCopy(on: rowView, target: .cell(0))
205+
206+
#expect(clipboard.text == "1\tAlice\n2\tBob")
207+
}
187208
}

0 commit comments

Comments
 (0)