Skip to content

Commit b3b44f4

Browse files
fix: fixed issue when undo of pasted collapsed sub-process throws JS Errors
Related to #2269
1 parent 8fa34d8 commit b3b44f4

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

lib/features/modeling/behavior/SubProcessPlaneBehavior.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,26 @@ export default function SubProcessPlaneBehavior(
111111
}, true);
112112

113113

114-
this.postExecuted('shape.create', function(context) {
115-
var shape = context.shape,
116-
rootElement = context.newRootElement;
114+
this.postExecuted('elements.create', function(context) {
115+
var elements = context.elements;
117116

118-
if (!rootElement || !shape.children) {
119-
return;
120-
}
117+
forEach(elements, function(element) {
118+
if (!isCollapsedSubProcess(element)) {
119+
return;
120+
}
121+
122+
var rootElement = elementRegistry.get(getPlaneIdFromShape(element));
121123

122-
self._showRecursively(shape.children);
124+
if (!rootElement || !element.children || !element.children.length) {
125+
return;
126+
}
123127

124-
self._moveChildrenToShape(shape.children.slice(), rootElement);
128+
var children = getSubProcessChildren(element);
129+
130+
self._showRecursively(children);
131+
132+
self._moveChildrenToShape(children, rootElement);
133+
});
125134
}, true);
126135

127136

@@ -359,11 +368,7 @@ export default function SubProcessPlaneBehavior(
359368
// since we can't keep both after collapsing
360369
self._disconnectSharedAnnotations(shape);
361370

362-
// annotations and external labels live at process level by design;
363-
// include them when moving children to the plane
364-
var children = shape.children.slice()
365-
.concat(collectAnnotationElements(shape.children))
366-
.concat(getExternalLabels(shape));
371+
var children = getSubProcessChildren(shape);
367372

368373
self._moveChildrenToShape(children, rootElement);
369374

@@ -652,6 +657,21 @@ function collectAnnotationElements(elements) {
652657
return result;
653658
}
654659

660+
/**
661+
* Collect all children of a collapsed subprocess that need to be moved
662+
* to or from its plane, including annotations and external labels that
663+
* live at the process level by design(ref: https://github.com/camunda/camunda-modeler/issues/5163#issuecomment-3946571271)
664+
*
665+
* @param {Element} element
666+
*
667+
* @return {Element[]}
668+
*/
669+
function getSubProcessChildren(element) {
670+
return element.children.slice()
671+
.concat(collectAnnotationElements(element.children))
672+
.concat(getExternalLabels(element));
673+
}
674+
655675
/**
656676
* Returns external labels of the given element's children and their descendants
657677
*
@@ -677,3 +697,4 @@ function getExternalLabels(element) {
677697

678698
return result;
679699
}
700+

0 commit comments

Comments
 (0)