diff --git a/lib/features/modeling/behavior/LabelBehavior.js b/lib/features/modeling/behavior/LabelBehavior.js index a94c9fdb..be11c09b 100644 --- a/lib/features/modeling/behavior/LabelBehavior.js +++ b/lib/features/modeling/behavior/LabelBehavior.js @@ -4,7 +4,9 @@ var assign = require('lodash/object/assign'), inherits = require('inherits'); var LabelUtil = require('../../../util/LabelUtil'), - is = require('../../../util/ModelUtil').is; + ModelUtil = require('../../../util/ModelUtil'), + is = ModelUtil.is, + getBusinessObject = ModelUtil.getBusinessObject; var hasExternalLabel = LabelUtil.hasExternalLabel, getExternalLabelMid = LabelUtil.getExternalLabelMid; @@ -68,6 +70,19 @@ function LabelSupport(eventBus, modeling, bpmnFactory) { } }); + this.postExecute([ 'shape.replace' ], function(e) { + var context = e.context, + newShape = context.newShape, + oldShape = context.oldShape; + + var businessObject = getBusinessObject(newShape); + + if (businessObject && hasExternalLabel(businessObject)) { + newShape.label.x = oldShape.label.x; + newShape.label.y = oldShape.label.y; + } + }); + // update di information on label creation this.executed([ 'label.create' ], function(e) { diff --git a/test/spec/features/replace/BpmnReplaceSpec.js b/test/spec/features/replace/BpmnReplaceSpec.js index c83e2283..6e0c2f43 100644 --- a/test/spec/features/replace/BpmnReplaceSpec.js +++ b/test/spec/features/replace/BpmnReplaceSpec.js @@ -247,6 +247,25 @@ describe('features/replace - bpmn replace', function() { expect(newElement.y).to.equal(task.y); })); + it('should keep label position', inject(function (elementRegistry, bpmnReplace, modeling) { + + // given + var exclusiveGateway = elementRegistry.get('ExclusiveGateway_1'); + var label = elementRegistry.get('ExclusiveGateway_1_label'); + + var newElementData = { + type: 'bpmn:InclusiveGateway' + }; + + // when + var newElement = bpmnReplace.replaceElement(exclusiveGateway, newElementData); + + // then + expect(newElement.label.x).to.equal(label.x); + expect(newElement.label.y).to.equal(label.y); + + })); + });