-
-
Notifications
You must be signed in to change notification settings - Fork 288
fix(datagrid): Delete key and right-click respect multi-row/cell-range selection #1648
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,12 @@ final class KeyHandlingTableView: NSTableView { | |
|
|
||
| @objc func delete(_ sender: Any?) { | ||
| guard coordinator?.isEditable == true else { return } | ||
| if let controller = gridSelection, !controller.isEmpty { | ||
| let rows = controller.selection.affectedRows | ||
| guard !rows.isEmpty else { return } | ||
| coordinator?.delegate?.dataGridDeleteRows(Set(rows)) | ||
| return | ||
| } | ||
| guard !selectedRowIndexes.isEmpty else { return } | ||
| coordinator?.delegate?.dataGridDeleteRows(Set(selectedRowIndexes)) | ||
| } | ||
|
|
@@ -279,7 +285,8 @@ final class KeyHandlingTableView: NSTableView { | |
| override func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool { | ||
| switch item.action { | ||
| case #selector(delete(_:)), #selector(deleteBackward(_:)): | ||
| return coordinator?.isEditable == true && !selectedRowIndexes.isEmpty | ||
| let hasGridSelection = gridSelection?.isEmpty == false | ||
| return coordinator?.isEditable == true && (hasGridSelection || !selectedRowIndexes.isEmpty) | ||
| case #selector(copy(_:)): | ||
| let hasGridSelection = gridSelection?.isEmpty == false | ||
| return hasGridSelection || !selectedRowIndexes.isEmpty | ||
|
|
@@ -407,7 +414,7 @@ final class KeyHandlingTableView: NSTableView { | |
|
|
||
| private func deleteSelectedRowsIfPossible() { | ||
| guard coordinator?.isEditable == true else { return } | ||
| guard !selectedRowIndexes.isEmpty else { return } | ||
| guard gridSelection?.isEmpty == false || !selectedRowIndexes.isEmpty else { return } | ||
| delete(nil) | ||
| } | ||
|
|
||
|
|
@@ -521,6 +528,19 @@ final class KeyHandlingTableView: NSTableView { | |
| scrollColumnToVisible(prevColumn) | ||
| } | ||
|
|
||
| override func rightMouseDown(with event: NSEvent) { | ||
| let point = convert(event.locationInWindow, from: nil) | ||
| let clickedRow = row(at: point) | ||
| if clickedRow >= 0, selectedRowIndexes.contains(clickedRow) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This fast path only recognizes rows in Useful? React with 👍 / 👎. |
||
| window?.makeFirstResponder(self) | ||
| if let menu = menu(for: event) { | ||
| NSMenu.popUpContextMenu(menu, with: event, for: self) | ||
| } | ||
| return | ||
| } | ||
| super.rightMouseDown(with: event) | ||
| } | ||
|
|
||
| override func menu(for event: NSEvent) -> NSMenu? { | ||
| let point = convert(event.locationInWindow, from: nil) | ||
| let clickedRow = row(at: point) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the selected range includes newly inserted rows,
dataGridDeleteRows(Set(rows))physically removes those rows, but the grid selection is left intact:applyRemovedRowsonly updates/removes table rows andsyncSelectionperforms the next row selection programmatically, sotableViewSelectionDidChangedoes not clearselectionController. After deleting a cell range over inserted rows, the Delete menu remains enabled from the stale grid selection and pressing Delete again deletes whatever rows shifted into the old indexes.Useful? React with 👍 / 👎.