fix(modeling): properly cascade label deletion
Ensure we execute the following nicely: * unset name -> remove label shape * remove label shape -> unset name
This commit is contained in:
parent
8bb34dacb2
commit
a7a1743df0
|
@ -54,7 +54,7 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
|
|||
if (!isLabel(element)
|
||||
&& isLabelExternal(element)
|
||||
&& !hasExternalLabel(element)
|
||||
&& newLabel !== '') {
|
||||
&& !isEmptyText(newLabel)) {
|
||||
|
||||
// create label
|
||||
var paddingTop = 7;
|
||||
|
@ -86,10 +86,14 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
|
|||
var element = ctx.element,
|
||||
label = element.label || element,
|
||||
newLabel = ctx.newLabel,
|
||||
newBounds = ctx.newBounds;
|
||||
newBounds = ctx.newBounds,
|
||||
hints = ctx.hints || {};
|
||||
|
||||
if (isLabel(label) && newLabel.trim() === '') {
|
||||
modeling.removeShape(label);
|
||||
if (isLabel(label) && isEmptyText(newLabel)) {
|
||||
|
||||
if (hints.removeShape !== false) {
|
||||
modeling.removeShape(label, { unsetLabel: false });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -132,3 +136,10 @@ UpdateLabelHandler.$inject = [
|
|||
'modeling',
|
||||
'textRenderer'
|
||||
];
|
||||
|
||||
|
||||
// helpers ///////////////////////
|
||||
|
||||
function isEmptyText(label) {
|
||||
return !label || !label.trim();
|
||||
}
|
|
@ -58,11 +58,12 @@ Modeling.prototype.getHandlers = function() {
|
|||
};
|
||||
|
||||
|
||||
Modeling.prototype.updateLabel = function(element, newLabel, newBounds) {
|
||||
Modeling.prototype.updateLabel = function(element, newLabel, newBounds, hints) {
|
||||
this._commandStack.execute('element.updateLabel', {
|
||||
element: element,
|
||||
newLabel: newLabel,
|
||||
newBounds: newBounds
|
||||
newBounds: newBounds,
|
||||
hints: hints || {}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -89,11 +89,12 @@ export default function LabelBehavior(
|
|||
// update label after label shape was deleted
|
||||
this.postExecute('shape.delete', function(event) {
|
||||
var context = event.context,
|
||||
shape = context;
|
||||
labelTarget = context.labelTarget,
|
||||
hints = context.hints || {};
|
||||
|
||||
// check if label
|
||||
if (shape.labelTarget) {
|
||||
modeling.updateLabel(shape.labelTarget, '');
|
||||
if (labelTarget && hints.unsetLabel !== false) {
|
||||
modeling.updateLabel(labelTarget, '', null, { removeShape: false });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -50,20 +50,40 @@ describe('features/modeling - update label', function() {
|
|||
));
|
||||
|
||||
|
||||
it('should delete label when setting empty string', inject(
|
||||
function(modeling, elementRegistry) {
|
||||
describe('should delete label', function() {
|
||||
|
||||
// given
|
||||
var startEvent_1 = elementRegistry.get('StartEvent_1');
|
||||
it('when setting null', inject(
|
||||
function(modeling, elementRegistry) {
|
||||
|
||||
// when
|
||||
modeling.updateLabel(startEvent_1, '');
|
||||
// given
|
||||
var startEvent_1 = elementRegistry.get('StartEvent_1');
|
||||
|
||||
// then
|
||||
expect(startEvent_1.businessObject.name).to.equal('');
|
||||
expect(startEvent_1.label).not.to.exist;
|
||||
}
|
||||
));
|
||||
// when
|
||||
modeling.updateLabel(startEvent_1, null);
|
||||
|
||||
// then
|
||||
expect(startEvent_1.businessObject.name).not.to.exist;
|
||||
expect(startEvent_1.label).not.to.exist;
|
||||
}
|
||||
));
|
||||
|
||||
|
||||
it('when setting empty string', inject(
|
||||
function(modeling, elementRegistry) {
|
||||
|
||||
// given
|
||||
var startEvent_1 = elementRegistry.get('StartEvent_1');
|
||||
|
||||
// when
|
||||
modeling.updateLabel(startEvent_1, '');
|
||||
|
||||
// then
|
||||
expect(startEvent_1.businessObject.name).to.equal('');
|
||||
expect(startEvent_1.label).not.to.exist;
|
||||
}
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should change name of start event when editing label', inject(
|
||||
|
|
Loading…
Reference in New Issue