Skip to content

Commit

Permalink
paste grid cell after the previous
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggi committed Oct 10, 2024
1 parent 647fb23 commit b740b83
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,36 @@ function pasteNextToSameSizedElement(
return null
}

function pasteIntoNextGridCell(
copyData: ParsedCopyData,
selectedViews: NonEmptyArray<ElementPath>,
metadata: ElementInstanceMetadataMap,
): ReparentTargetForPaste | null {
if (selectedViews.length === 0) {
return null
}
const selectedView = lastOfNonEmptyArray(selectedViews)

// if the copied elements are grid cells and the target is a grid cell, paste next to it

const copyDataElementsAreGridCells = copyData.elementPaste.every(({ originalElementPath }) =>
MetadataUtils.isGridCell(copyData.originalContextMetadata, originalElementPath),
)
if (!copyDataElementsAreGridCells) {
return null
}

const targetIsGridCell = MetadataUtils.isGridCell(metadata, selectedView)
if (!targetIsGridCell) {
return null
}

return {
type: 'parent',
parentPath: childInsertionPath(EP.parentPath(selectedView)),
}
}

function canInsertIntoTarget(
projectContents: ProjectContentTreeRoot,
metadata: ElementInstanceMetadataMap,
Expand Down Expand Up @@ -762,6 +792,11 @@ export function getTargetParentForPaste(
return right(pasteNextToSameSizedElementResult)
}

const paseIntoNextGridCellResult = pasteIntoNextGridCell(copyData, selectedViews, metadata)
if (paseIntoNextGridCellResult != null) {
return right(paseIntoNextGridCellResult)
}

const pasteIntoParentOrGrandparentResult = pasteIntoParentOrGrandparent(
copyData.elementPaste.map((e) => e.element),
projectContents,
Expand Down

0 comments on commit b740b83

Please sign in to comment.