diff --git a/lib/features/modeling/behavior/SubProcessPlaneBehavior.js b/lib/features/modeling/behavior/SubProcessPlaneBehavior.js
index c4eb466e..d1400bba 100644
--- a/lib/features/modeling/behavior/SubProcessPlaneBehavior.js
+++ b/lib/features/modeling/behavior/SubProcessPlaneBehavior.js
@@ -95,6 +95,41 @@ export default function SubProcessPlaneBehavior(
}, true);
+ this.preExecuted('shape.delete', function(context) {
+ var shape = context.shape;
+ if (!isCollapsedSubProcess(shape)) {
+ return;
+ }
+
+ var attachedRoot = elementRegistry.get(planeId(shape));
+
+ if (!attachedRoot) {
+ return;
+ }
+
+ modeling.removeElements(attachedRoot.children.slice());
+ }, true);
+
+
+ this.executed('shape.delete', function(context) {
+ var shape = context.shape;
+ if (!isCollapsedSubProcess(shape)) {
+ return;
+ }
+ removeRoot(context);
+ }, true);
+
+
+ this.reverted('shape.delete', function(context) {
+ var shape = context.shape;
+ if (!isCollapsedSubProcess(shape)) {
+ return;
+ }
+
+ createRoot(context);
+ }, true);
+
+
this.preExecuted('shape.replace', function(context) {
var oldShape = context.oldShape;
var newShape = context.newShape;
diff --git a/test/spec/features/drilldown/legacy-subprocesses.bpmn b/test/spec/features/drilldown/legacy-subprocesses.bpmn
index 4626c1f7..777823e0 100644
--- a/test/spec/features/drilldown/legacy-subprocesses.bpmn
+++ b/test/spec/features/drilldown/legacy-subprocesses.bpmn
@@ -17,6 +17,7 @@
+
@@ -37,15 +38,18 @@
+
+
+
-
-
+
+
-
+
\ No newline at end of file
diff --git a/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js b/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js
index 563626c7..1d6e7c55 100644
--- a/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js
+++ b/test/spec/features/modeling/behavior/SubProcessPlaneBehaviorSpec.js
@@ -197,6 +197,71 @@ describe('features/modeling/behavior - subprocess planes', function() {
});
+
+ describe('remove', function() {
+
+ var multipleDiagramXML = require('./SubProcessBehavior.multiple-planes.bpmn');
+
+ beforeEach(bootstrapModeler(multipleDiagramXML, {
+ modules: [
+ coreModule,
+ modelingModule,
+ replaceModule
+ ]
+ }));
+
+ it('should recursively remove diagrams', inject(function(elementRegistry, modeling, bpmnjs) {
+
+ // given
+ var subProcess = elementRegistry.get('SubProcess_2');
+
+ // when
+ modeling.removeShape(subProcess);
+
+ // then
+ var nestedTask = elementRegistry.get('nested_task');
+ var diagrams = bpmnjs.getDefinitions().diagrams;
+ expect(diagrams.length).to.equal(1);
+ expect(nestedTask).to.not.exist;
+ }));
+
+
+ it('should undo', inject(function(elementRegistry, modeling, bpmnjs, commandStack) {
+
+ // given
+ var subProcess = elementRegistry.get('SubProcess_2');
+ modeling.removeShape(subProcess);
+
+ // when
+ commandStack.undo();
+
+ // then
+ var nestedTask = elementRegistry.get('nested_task');
+ var diagrams = bpmnjs.getDefinitions().diagrams;
+ expect(diagrams.length).to.equal(3);
+ expect(nestedTask).to.exist;
+ }));
+
+
+ it('should undo', inject(function(elementRegistry, modeling, bpmnjs, commandStack) {
+
+ // given
+ var subProcess = elementRegistry.get('SubProcess_2');
+ modeling.removeShape(subProcess);
+
+ // when
+ commandStack.undo();
+ commandStack.redo();
+
+ // then
+ var nestedTask = elementRegistry.get('nested_task');
+ var diagrams = bpmnjs.getDefinitions().diagrams;
+ expect(diagrams.length).to.equal(1);
+ expect(nestedTask).to.not.exist;
+ }));
+
+ });
+
});