@@ -374,6 +374,7 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
374374 const sourceCell = model . sourceForCell ( modelColumn , modelRow ) ;
375375 const { column : sourceColumn , row : sourceRow } = sourceCell ;
376376 const value = model . valueForCell ( sourceColumn , sourceRow ) ;
377+ const { selectedRanges } = irisGrid . state ;
377378
378379 const column = columns [ sourceColumn ] ;
379380
@@ -480,30 +481,54 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
480481 } ) ;
481482 }
482483
483- actions . push ( {
484- title : 'Paste' ,
485- group : IrisGridContextMenuHandler . GROUP_COPY ,
486- order : 50 ,
487- action : async ( ) => {
488- try {
489- const text = await readFromClipboard ( ) ;
490- const items = text . split ( '\n' ) . map ( row => row . split ( '\t' ) ) ;
491- await grid . pasteValue ( items ) ;
492- } catch ( err ) {
493- if ( err instanceof ClipboardUnavailableError ) {
494- irisGrid . handleOpenNoPastePermissionModal (
495- 'For security reasons your browser does not allow access to your clipboard on click.'
496- ) ;
497- } else if ( err instanceof ClipboardPermissionsDeniedError ) {
498- irisGrid . handleOpenNoPastePermissionModal (
499- 'Requested clipboard permissions have not been granted, please grant them and try again.'
500- ) ;
501- } else {
502- throw err ;
503- }
504- }
505- } ,
506- } ) ;
484+ if ( isEditableGridModel ( model ) && model . isEditable ) {
485+ // selectedRanges is updated by GridSelectionMouseHandler in the same cycle so can't access the updated value here
486+ // so need to handle cases where a cell is right clicked without highlighting it first
487+ const canPasteInOriginalRange = selectedRanges . every ( range =>
488+ model . isEditableRange ( range )
489+ ) ;
490+
491+ // To account for how when a cell outside of a selection is right clicked, that selection gets cleared
492+ const isCellInOriginalRange = GridRange . containsCell (
493+ selectedRanges ,
494+ columnIndex ,
495+ rowIndex
496+ ) ;
497+
498+ const canPasteInCell = model . isEditableRange (
499+ GridRange . makeCell ( columnIndex , rowIndex )
500+ ) ;
501+
502+ if (
503+ ( canPasteInOriginalRange || ! isCellInOriginalRange ) &&
504+ canPasteInCell
505+ ) {
506+ actions . push ( {
507+ title : 'Paste' ,
508+ group : IrisGridContextMenuHandler . GROUP_COPY ,
509+ order : 50 ,
510+ action : async ( ) => {
511+ try {
512+ const text = await readFromClipboard ( ) ;
513+ const items = text . split ( '\n' ) . map ( row => row . split ( '\t' ) ) ;
514+ await grid . pasteValue ( items ) ;
515+ } catch ( err ) {
516+ if ( err instanceof ClipboardUnavailableError ) {
517+ irisGrid . handleOpenNoPastePermissionModal (
518+ 'For security reasons your browser does not allow access to your clipboard on click.'
519+ ) ;
520+ } else if ( err instanceof ClipboardPermissionsDeniedError ) {
521+ irisGrid . handleOpenNoPastePermissionModal (
522+ 'Requested clipboard permissions have not been granted, please grant them and try again.'
523+ ) ;
524+ } else {
525+ throw err ;
526+ }
527+ }
528+ } ,
529+ } ) ;
530+ }
531+ }
507532
508533 actions . push ( {
509534 title : 'View Cell Contents' ,
0 commit comments