refactor(datagrid): make Cmd+C and Cmd+Shift+C robust when focus left the grid#1338
Merged
Conversation
This was referenced May 19, 2026
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
Follow-up to #1337. Two open items from the post-merge review of that PR:
Responder-chain regression for
.copyRows. After feat(datagrid): copy focused cell value with Cmd+C, add Cmd+Shift+C for rows (#1332) #1337, both Cmd+C (when router resolves to.copyRows) and Cmd+Shift+C dispatch the action viaNSApp.sendAction(_:to:nil:from:). If the first responder isn't in a chain that reachesKeyHandlingTableView(e.g. focus moved to a different text field while a row selection persists in the grid), the action is silently lost. Before feat(datagrid): copy focused cell value with Cmd+C, add Cmd+Shift+C for rows (#1332) #1337, the menu button calledactions?.copySelectedRows()directly, which didn't depend on responder chain.CreateTableViewhas the same selection-mirror problemTableStructureViewhad:@State selectedRowsnever feedsGridSelectionState.indices, so.disabled(!hasRowSelection)on the new "Copy Rows" menu item stays true and Cmd+Shift+C is blocked.Changes
PasteboardCommands: both the "Copy".copyRowsbranch and the "Copy Rows" button now fall back toactions?.copySelectedRows()whenNSApp.sendActionreturnsfalse. Responder chain stays the preferred path; the SwiftUI-side action is the safety net.CreateTableView: takesselectionState: GridSelectionState, mirrorsselectedRowsinto it via.onChange(of:), and clears it.onDisappear. Same patternTableStructureViewalready uses.MainEditorContentView: passesselectionStateinto theCreateTableViewcall site.Why this is the right shape
validateUserInterfaceItemonKeyHandlingTableViewcontinues to guardcopy:andcopyRowsAsTSV:..copyCellValue, there's no fallback needed because cell-copy only fires when the user can see the focus border, which requires the table view to be the active emphasized responder, which means the responder chain will reach it.Test plan
xcodebuild -project TablePro.xcodeproj -scheme TablePro test -skipPackagePluginValidationCmd+Shift+C— clipboard contains the row TSV (was silently lost before this PR)Cmd+C— clipboard contains the row TSVCmd+Shift+C— clipboard contains the structure-row payloadCmd+Ccopies the cell, multi-row select +Cmd+Ccopies TSV