-
-
Notifications
You must be signed in to change notification settings - Fork 143
fix(datagrid): route Cmd+V to row paste when clipboard holds copied rows #935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
103 changes: 103 additions & 0 deletions
103
TableProTests/Views/Results/Extensions/CellPasteRoutingTests.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // | ||
| // CellPasteRoutingTests.swift | ||
| // TableProTests | ||
| // | ||
| // Locks the contract that pasteCellsFromClipboard defers to row paste | ||
| // when the clipboard carries the in-app gridRows tag or has a row-shaped | ||
| // TSV. Without these checks, Cmd+V on a focused cell after Cmd+C on a row | ||
| // silently overwrites the row's tail columns. | ||
| // | ||
|
|
||
| import AppKit | ||
| import Foundation | ||
| import SwiftUI | ||
| import Testing | ||
| @testable import TablePro | ||
|
|
||
| @MainActor | ||
| private final class StubClipboard: ClipboardProvider { | ||
| var text: String? | ||
| var hasGridRowsValue = false | ||
|
|
||
| func readText() -> String? { text } | ||
| func writeText(_ text: String) { self.text = text; hasGridRowsValue = false } | ||
| func writeRows(tsv: String, html: String?) { self.text = tsv; hasGridRowsValue = true } | ||
| var hasText: Bool { text != nil } | ||
| var hasGridRows: Bool { hasGridRowsValue } | ||
| } | ||
|
|
||
| @Suite("pasteCellsFromClipboard routing") | ||
| @MainActor | ||
| struct CellPasteRoutingTests { | ||
| private func makeCoordinator(columns: [String], rowCount: Int) -> TableViewCoordinator { | ||
| let coordinator = TableViewCoordinator( | ||
| changeManager: AnyChangeManager(DataChangeManager()), | ||
| isEditable: true, | ||
| selectedRowIndices: .constant([]), | ||
| delegate: nil | ||
| ) | ||
| let columnTypes: [ColumnType] = Array(repeating: .text(rawType: nil), count: columns.count) | ||
| let rows = (0..<rowCount).map { i in (0..<columns.count).map { c in "r\(i)c\(c)" } } | ||
| let tableRows = TableRows.from(queryRows: rows, columns: columns, columnTypes: columnTypes) | ||
| coordinator.tableRowsProvider = { tableRows } | ||
| coordinator.updateCache() | ||
| return coordinator | ||
| } | ||
|
|
||
| @Test("Defers to row paste when clipboard has gridRows tag") | ||
| func defersOnGridRowsTag() { | ||
| let stub = StubClipboard() | ||
| stub.text = "anything\twith\ttabs" | ||
| stub.hasGridRowsValue = true | ||
| ClipboardService.shared = stub | ||
|
|
||
| let coordinator = makeCoordinator(columns: ["a", "b", "c"], rowCount: 5) | ||
| let result = coordinator.pasteCellsFromClipboard(anchorRow: 0, anchorColumn: 0) | ||
|
|
||
| #expect(result == false) | ||
| } | ||
|
|
||
| @Test("Defers to row paste when every TSV line matches column count") | ||
| func defersOnRowShapedTSV() { | ||
| let stub = StubClipboard() | ||
| stub.text = "x\ty\tz\nq\tw\te" | ||
| stub.hasGridRowsValue = false | ||
| ClipboardService.shared = stub | ||
|
|
||
| let coordinator = makeCoordinator(columns: ["a", "b", "c"], rowCount: 5) | ||
| let result = coordinator.pasteCellsFromClipboard(anchorRow: 0, anchorColumn: 0) | ||
|
|
||
| #expect(result == false) | ||
| } | ||
|
|
||
| @Test("Cell pastes shape-mismatched TSV into focused range") | ||
| func cellPastesShapeMismatchedTSV() { | ||
| let stub = StubClipboard() | ||
| stub.text = "x\ty" | ||
| stub.hasGridRowsValue = false | ||
| ClipboardService.shared = stub | ||
|
|
||
| let coordinator = makeCoordinator(columns: ["a", "b", "c", "d", "e"], rowCount: 5) | ||
| let result = coordinator.pasteCellsFromClipboard(anchorRow: 0, anchorColumn: 0) | ||
|
|
||
| #expect(result == true) | ||
| } | ||
|
|
||
| @Test("Returns false when not editable") | ||
| func refusesWhenReadOnly() { | ||
| let stub = StubClipboard() | ||
| stub.text = "x\ty" | ||
| ClipboardService.shared = stub | ||
|
|
||
| let coordinator = TableViewCoordinator( | ||
| changeManager: AnyChangeManager(DataChangeManager()), | ||
| isEditable: false, | ||
| selectedRowIndices: .constant([]), | ||
| delegate: nil | ||
| ) | ||
|
|
||
| let result = coordinator.pasteCellsFromClipboard(anchorRow: 0, anchorColumn: 0) | ||
|
|
||
| #expect(result == false) | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.