@@ -610,6 +610,8 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
610610
611611 const lastSelectedRowRef = React . useRef < number > ( ) ;
612612 const lastSelectedColRef = React . useRef < number > ( ) ;
613+
614+ const lastMouseDownCellLocation = React . useRef < [ number , number ] > ( ) ;
613615 const onMouseDown = React . useCallback (
614616 ( args : GridMouseEventArgs ) => {
615617 if ( args . button !== 0 ) {
@@ -618,10 +620,16 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
618620 mouseState . current = {
619621 previousSelection : gridSelection ,
620622 } ;
623+
624+ lastMouseDownCellLocation . current = undefined ;
625+
621626 const isMultiKey = browserIsOSX . value ? args . metaKey : args . ctrlKey ;
627+ const [ col , row ] = args . location ;
622628 if ( args . kind === "cell" ) {
623629 lastSelectedColRef . current = undefined ;
624- const [ col , row ] = args . location ;
630+
631+ lastMouseDownCellLocation . current = [ col , row ] ;
632+
625633 if ( col === 0 && hasRowMarkers ) {
626634 if ( ( showTrailingBlankRow === true && row === rows ) || rowMarkers === "number" ) return ;
627635 setGridSelection ( undefined ) ;
@@ -695,7 +703,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
695703 }
696704 }
697705 } else if ( args . kind === "header" ) {
698- const [ col ] = args . location ;
706+ lastMouseDownCellLocation . current = [ col , row ] ;
699707 setGridSelection ( undefined ) ;
700708 setOverlay ( undefined ) ;
701709 if ( hasRowMarkers && col === 0 ) {
@@ -741,7 +749,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
741749 lastSelectedRowRef . current = undefined ;
742750 lastSelectedColRef . current = undefined ;
743751 } else if ( args . kind === "group-header" ) {
744- const [ col ] = args . location ;
752+ lastMouseDownCellLocation . current = [ col , row ] ;
745753
746754 if ( col < rowMarkerOffset ) return ;
747755
@@ -817,16 +825,19 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
817825 window . clearInterval ( scrollTimer . current ) ;
818826 }
819827
828+ const [ lastMouseDownCol , lastMouseDownRow ] = lastMouseDownCellLocation . current ?? [ ] ;
829+ const [ col , row ] = args . location ;
830+
820831 if ( args . kind === "header" ) {
821- if ( args . button === 0 ) {
832+ if ( args . button === 0 && col === lastMouseDownCol && row === lastMouseDownRow ) {
822833 onHeaderClicked ?.( args . location [ 0 ] - rowMarkerOffset , { ...args , preventDefault } ) ;
823834 } else if ( args . button === 2 ) {
824835 onHeaderContextMenu ?.( args . location [ 0 ] - rowMarkerOffset , { ...args , preventDefault } ) ;
825836 }
826837 }
827838
828839 if ( args . kind === "group-header" ) {
829- if ( args . button === 0 ) {
840+ if ( args . button === 0 && col === lastMouseDownCol && row === lastMouseDownRow ) {
830841 onGroupHeaderClicked ?.( args . location [ 0 ] - rowMarkerOffset , { ...args , preventDefault } ) ;
831842 } else if ( args . button === 2 ) {
832843 onGroupHeaderContextMenu ?.( args . location [ 0 ] - rowMarkerOffset , { ...args , preventDefault } ) ;
@@ -837,9 +848,13 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
837848 return ;
838849 }
839850 if ( args . button === 0 ) {
840- onCellClicked ?.( [ args . location [ 0 ] - rowMarkerOffset , args . location [ 1 ] ] , { ...args , preventDefault } ) ;
851+ if ( lastMouseDownCol === col && lastMouseDownRow === row ) {
852+ onCellClicked ?.( [ col - rowMarkerOffset , row ] , {
853+ ...args ,
854+ preventDefault,
855+ } ) ;
856+ }
841857 if ( gridSelection !== undefined && mouse ?. previousSelection ?. cell !== undefined && ! prevented ) {
842- const [ col , row ] = args . location ;
843858 const [ selectedCol , selectedRow ] = gridSelection . cell ;
844859 const [ prevCol , prevRow ] = mouse . previousSelection . cell ;
845860 const c = getMangedCellContent ( [ col , row ] ) ;
0 commit comments