fix(replace): preserve label position on element replace

closes #235
This commit is contained in:
Philipp Fromme 2016-04-18 13:04:32 +02:00 committed by Ricardo Matias
parent 7de043ab9d
commit ec159381ce
2 changed files with 35 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
}));
});