Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uid duplication during paste #4833

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
offsetPoint,
} from '../../../../core/shared/math-utils'
import type { CanvasPoint } from '../../../../core/shared/math-utils'
import { optionalMap } from '../../../../core/shared/optional-utils'
import type {
ElementPath,
ElementPathPart,
Expand All @@ -42,6 +43,7 @@ import type {
import { trueUpGroupElementChanged } from '../../../editor/store/editor-state'
import {
childInsertionPath,
getFragmentUidFromInsertionPath,
replaceWithElementsWrappedInFragmentBehaviour,
} from '../../../editor/store/insertion-path'
import type { CanvasCommand } from '../../commands/commands'
Expand Down Expand Up @@ -166,7 +168,10 @@ function pasteChoiceCommon(
)
: front()

let fixedUIDMappingNewUIDS: Array<string> = []
let fixedUIDMappingNewUIDS: Array<string> =
optionalMap((wrapperUid) => [wrapperUid], getFragmentUidFromInsertionPath(target.parentPath)) ??
[]

let oldPathToNewPathMapping: OldPathToNewPathMapping = {}
const elementsToInsert: Array<ElementOrPathToInsert> =
pasteContext.elementPasteWithMetadata.elements.map((elementPaste) => {
Expand Down
24 changes: 24 additions & 0 deletions editor/src/components/editor/store/insertion-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ export function insertionPathToString(insertionPath: InsertionPath): string {
assertNever(insertionPath)
}
}
export function getFragmentUidFromInsertionBehaviour(
insertionBehaviour: ConditionalClauseInsertBehavior,
): string | null {
switch (insertionBehaviour.type) {
case 'replace-with-elements-wrapped-in-fragment':
case 'wrap-in-fragment-and-append-elements':
return insertionBehaviour.fragmentUID
case 'replace-with-single-element':
return null
default:
assertNever(insertionBehaviour)
}
}

export function getFragmentUidFromInsertionPath(insertionPath: InsertionPath): string | null {
switch (insertionPath.type) {
case 'CHILD_INSERTION':
return null
case 'CONDITIONAL_CLAUSE_INSERTION':
return getFragmentUidFromInsertionBehaviour(insertionPath.insertBehavior)
default:
assertNever(insertionPath)
}
}

export function commonInsertionPath(
metadata: ElementInstanceMetadataMap,
Expand Down
Loading