Skip to content

Commit

Permalink
Fix uid duplication during paste (#4833)
Browse files Browse the repository at this point in the history
* `getFragmentUidFromInsertionPath`

* cehck wrapper uid
  • Loading branch information
bkrmendy authored Feb 5, 2024
1 parent ceedc4a commit 4323eed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 4323eed

Please sign in to comment.