Skip to content

Commit 06a3fd4

Browse files
committed
fix: improve row selection handling and clean up code, fixes: #1504
1 parent d7fa45b commit 06a3fd4

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

ui/studio/grid/DataGrid.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ export function DataGrid(props: DataGridProps) {
927927
});
928928
const shouldEnablePreview = Boolean(
929929
dragDropTarget.compatibleOverId &&
930-
dragDropTarget.compatibleOverId !== activeId,
930+
dragDropTarget.compatibleOverId !== activeId,
931931
);
932932
setIsColumnReorderPreviewEnabled((current) =>
933933
current === shouldEnablePreview ? current : shouldEnablePreview,
@@ -1470,8 +1470,8 @@ export function DataGrid(props: DataGridProps) {
14701470
const text = hasRowSelection
14711471
? getSelectedRowClipboardText()
14721472
: hasCellSelection
1473-
? getSelectedClipboardText()
1474-
: getFocusedCellClipboardText();
1473+
? getSelectedClipboardText()
1474+
: getFocusedCellClipboardText();
14751475

14761476
if (!text) {
14771477
return;
@@ -2064,12 +2064,26 @@ export function DataGrid(props: DataGridProps) {
20642064
return;
20652065
}
20662066

2067-
selectSingleRowMode({ rowId, rowIndex, drag: isPrimaryButton });
2067+
clearNativeTextSelection();
2068+
clearCellSelectionState();
2069+
2070+
const nextSelection = { ...rowSelectionState };
2071+
2072+
if (nextSelection[rowId]) {
2073+
delete nextSelection[rowId];
2074+
} else {
2075+
nextSelection[rowId] = true;
2076+
}
2077+
2078+
setRowSelection(nextSelection);
2079+
2080+
rowSelectionDragRef.current = isPrimaryButton;
2081+
rowSelectionAnchorRef.current = rowIndex;
20682082
},
20692083
[
20702084
clearCellSelectionState,
2085+
clearNativeTextSelection,
20712086
rowSelectionState,
2072-
selectSingleRowMode,
20732087
setRowSelection,
20742088
],
20752089
);

0 commit comments

Comments
 (0)