diff --git a/lib/features/label-editing/cmd/UpdateLabelHandler.js b/lib/features/label-editing/cmd/UpdateLabelHandler.js index 7ef85dc1..ebe92d26 100644 --- a/lib/features/label-editing/cmd/UpdateLabelHandler.js +++ b/lib/features/label-editing/cmd/UpdateLabelHandler.js @@ -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; } @@ -131,4 +135,11 @@ export default function UpdateLabelHandler(modeling, textRenderer) { UpdateLabelHandler.$inject = [ 'modeling', 'textRenderer' -]; \ No newline at end of file +]; + + +// helpers /////////////////////// + +function isEmptyText(label) { + return !label || !label.trim(); +} \ No newline at end of file diff --git a/lib/features/modeling/Modeling.js b/lib/features/modeling/Modeling.js index 3e54c444..4af7d064 100644 --- a/lib/features/modeling/Modeling.js +++ b/lib/features/modeling/Modeling.js @@ -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 || {} }); }; diff --git a/lib/features/modeling/behavior/LabelBehavior.js b/lib/features/modeling/behavior/LabelBehavior.js index 5dc5a52e..072463e5 100644 --- a/lib/features/modeling/behavior/LabelBehavior.js +++ b/lib/features/modeling/behavior/LabelBehavior.js @@ -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 }); } }); diff --git a/test/spec/features/modeling/UpdateLabelSpec.js b/test/spec/features/modeling/UpdateLabelSpec.js index 9d1eb25d..defb8af7 100644 --- a/test/spec/features/modeling/UpdateLabelSpec.js +++ b/test/spec/features/modeling/UpdateLabelSpec.js @@ -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(