@@ -3220,6 +3220,42 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
32203220
32213221 const overlayOpen = overlay !== undefined ;
32223222
3223+ const onContextMenu = React . useCallback (
3224+ ( args : GridMouseEventArgs , preventDefault : ( ) => void ) => {
3225+ const adjustedCol = args . location [ 0 ] - rowMarkerOffset ;
3226+ if ( args . kind === "header" ) {
3227+ onHeaderContextMenu ?.( adjustedCol , { ...args , preventDefault } ) ;
3228+ }
3229+
3230+ if ( args . kind === groupHeaderKind ) {
3231+ if ( adjustedCol < 0 ) {
3232+ return ;
3233+ }
3234+ onGroupHeaderContextMenu ?.( adjustedCol , { ...args , preventDefault } ) ;
3235+ }
3236+
3237+ if ( args . kind === "cell" ) {
3238+ const [ col , row ] = args . location ;
3239+ onCellContextMenu ?.( [ adjustedCol , row ] , {
3240+ ...args ,
3241+ preventDefault,
3242+ } ) ;
3243+
3244+ if ( ! gridSelectionHasItem ( gridSelection , args . location ) ) {
3245+ updateSelectedCell ( col , row , false , false ) ;
3246+ }
3247+ }
3248+ } ,
3249+ [
3250+ gridSelection ,
3251+ onCellContextMenu ,
3252+ onGroupHeaderContextMenu ,
3253+ onHeaderContextMenu ,
3254+ rowMarkerOffset ,
3255+ updateSelectedCell ,
3256+ ]
3257+ ) ;
3258+
32233259 const handleFixedKeybindings = React . useCallback (
32243260 ( event : GridKeyEventArgs ) : boolean => {
32253261 const cancel = ( ) => {
@@ -3397,6 +3433,35 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
33973433 col = Number . MAX_SAFE_INTEGER ;
33983434 } else if ( isHotkey ( keys . goToFirstColumn , event , details ) ) {
33993435 col = Number . MIN_SAFE_INTEGER ;
3436+ } else if (
3437+ isHotkey ( keys . contextMenu , event , details ) &&
3438+ bounds !== undefined &&
3439+ event . location !== undefined
3440+ ) {
3441+ const {
3442+ location,
3443+ ctrlKey,
3444+ metaKey,
3445+ shiftKey,
3446+ } = event ;
3447+
3448+ onContextMenu (
3449+ {
3450+ kind : "cell" ,
3451+ isFillHandle : false ,
3452+ isTouch : false ,
3453+ isEdge : false ,
3454+ button : 0 ,
3455+ scrollEdge : [ 0 , 0 ] ,
3456+ localEventX : bounds . width / 2 ,
3457+ localEventY : bounds . height / 2 ,
3458+ location,
3459+ bounds,
3460+ ctrlKey,
3461+ metaKey,
3462+ shiftKey,
3463+ buttons : 0
3464+ } , cancel )
34003465 } else if ( rangeSelect === "rect" || rangeSelect === "multi-rect" ) {
34013466 if ( isHotkey ( keys . selectGrowDown , event , details ) ) {
34023467 adjustSelection ( [ 0 , 1 ] ) ;
@@ -3486,6 +3551,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
34863551 return didMatch ;
34873552 } ,
34883553 [
3554+ onContextMenu ,
34893555 rowGroupingNavBehavior ,
34903556 overlayOpen ,
34913557 gridSelection ,
@@ -3579,42 +3645,6 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
35793645 ]
35803646 ) ;
35813647
3582- const onContextMenu = React . useCallback (
3583- ( args : GridMouseEventArgs , preventDefault : ( ) => void ) => {
3584- const adjustedCol = args . location [ 0 ] - rowMarkerOffset ;
3585- if ( args . kind === "header" ) {
3586- onHeaderContextMenu ?.( adjustedCol , { ...args , preventDefault } ) ;
3587- }
3588-
3589- if ( args . kind === groupHeaderKind ) {
3590- if ( adjustedCol < 0 ) {
3591- return ;
3592- }
3593- onGroupHeaderContextMenu ?.( adjustedCol , { ...args , preventDefault } ) ;
3594- }
3595-
3596- if ( args . kind === "cell" ) {
3597- const [ col , row ] = args . location ;
3598- onCellContextMenu ?.( [ adjustedCol , row ] , {
3599- ...args ,
3600- preventDefault,
3601- } ) ;
3602-
3603- if ( ! gridSelectionHasItem ( gridSelection , args . location ) ) {
3604- updateSelectedCell ( col , row , false , false ) ;
3605- }
3606- }
3607- } ,
3608- [
3609- gridSelection ,
3610- onCellContextMenu ,
3611- onGroupHeaderContextMenu ,
3612- onHeaderContextMenu ,
3613- rowMarkerOffset ,
3614- updateSelectedCell ,
3615- ]
3616- ) ;
3617-
36183648 const onPasteInternal = React . useCallback (
36193649 async ( e ?: ClipboardEvent ) => {
36203650 if ( ! keybindings . paste ) return ;
0 commit comments