@@ -538,6 +538,36 @@ function pasteNextToSameSizedElement(
538
538
return null
539
539
}
540
540
541
+ function pasteIntoNextGridCell (
542
+ copyData : ParsedCopyData ,
543
+ selectedViews : NonEmptyArray < ElementPath > ,
544
+ metadata : ElementInstanceMetadataMap ,
545
+ ) : ReparentTargetForPaste | null {
546
+ if ( selectedViews . length === 0 ) {
547
+ return null
548
+ }
549
+ const selectedView = lastOfNonEmptyArray ( selectedViews )
550
+
551
+ // if the copied elements are grid cells and the target is a grid cell, paste next to it
552
+
553
+ const copyDataElementsAreGridCells = copyData . elementPaste . every ( ( { originalElementPath } ) =>
554
+ MetadataUtils . isGridCell ( copyData . originalContextMetadata , originalElementPath ) ,
555
+ )
556
+ if ( ! copyDataElementsAreGridCells ) {
557
+ return null
558
+ }
559
+
560
+ const targetIsGridChild = MetadataUtils . isGridCell ( metadata , selectedView )
561
+ if ( ! targetIsGridChild ) {
562
+ return null
563
+ }
564
+
565
+ return {
566
+ type : 'parent' ,
567
+ parentPath : childInsertionPath ( EP . parentPath ( selectedView ) ) ,
568
+ }
569
+ }
570
+
541
571
function canInsertIntoTarget (
542
572
projectContents : ProjectContentTreeRoot ,
543
573
metadata : ElementInstanceMetadataMap ,
@@ -762,6 +792,11 @@ export function getTargetParentForPaste(
762
792
return right ( pasteNextToSameSizedElementResult )
763
793
}
764
794
795
+ const paseIntoNextGridCellResult = pasteIntoNextGridCell ( copyData , selectedViews , metadata )
796
+ if ( paseIntoNextGridCellResult != null ) {
797
+ return right ( paseIntoNextGridCellResult )
798
+ }
799
+
765
800
const pasteIntoParentOrGrandparentResult = pasteIntoParentOrGrandparent (
766
801
copyData . elementPaste . map ( ( e ) => e . element ) ,
767
802
projectContents ,
0 commit comments