diff --git a/lib/features/modeling/behavior/MoveStartEventBehavior.js b/lib/features/modeling/behavior/MoveStartEventBehavior.js index 77e639e5..9739013a 100644 --- a/lib/features/modeling/behavior/MoveStartEventBehavior.js +++ b/lib/features/modeling/behavior/MoveStartEventBehavior.js @@ -11,16 +11,16 @@ var isEventSubProcess = require('../../../util/DiUtil').isEventSubProcess; /** * Defines the behavior when a start event is moved */ -function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistry) { - +function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistry, selection) { CommandInterceptor.call(this, eventBus); this.postExecuted([ 'elements.move' ], function(event) { - var target = event.context.newParent, + var context = event.context, + target = context.newParent, elements = []; - forEach(event.context.closure.topLevel, function(topLevelElements) { + forEach(context.closure.topLevel, function(topLevelElements) { if (isEventSubProcess(topLevelElements)) { elements = elements.concat(topLevelElements.children); } else { @@ -30,17 +30,27 @@ function MoveStartEventBehavior(eventBus, bpmnReplace, bpmnRules, elementRegistr var canReplace = bpmnRules.canReplace(elements, target); - forEach(canReplace.replace, function(newElementData) { + forEach(canReplace.replace, function(replacements) { + var newElement = { - type: newElementData.type + type: replacements.newElementType }; - bpmnReplace.replaceElement(elementRegistry.get(newElementData.id), newElement); + var oldElement = elementRegistry.get(replacements.oldElementId); + + var idx = elements.indexOf(oldElement); + elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false }); + }); + + if (canReplace.replace) { + selection.select(elements); + } + }); } -MoveStartEventBehavior.$inject = [ 'eventBus', 'bpmnReplace', 'bpmnRules', 'elementRegistry' ]; +MoveStartEventBehavior.$inject = [ 'eventBus', 'bpmnReplace', 'bpmnRules', 'elementRegistry', 'selection' ]; inherits(MoveStartEventBehavior, CommandInterceptor); diff --git a/lib/features/modeling/rules/BpmnRules.js b/lib/features/modeling/rules/BpmnRules.js index ff4407a5..d2d03c78 100644 --- a/lib/features/modeling/rules/BpmnRules.js +++ b/lib/features/modeling/rules/BpmnRules.js @@ -431,8 +431,8 @@ function canReplace(elements, target) { canDrop(element, target)) { canExecute.replace.push({ - id: element.id, - type: 'bpmn:StartEvent' + oldElementId: element.id, + newElementType: 'bpmn:StartEvent' }); } } diff --git a/lib/features/replace-preview/BpmnReplacePreview.js b/lib/features/replace-preview/BpmnReplacePreview.js index 105fce65..953d1c98 100644 --- a/lib/features/replace-preview/BpmnReplacePreview.js +++ b/lib/features/replace-preview/BpmnReplacePreview.js @@ -23,12 +23,12 @@ function BpmnReplacePreview(eventBus, elementRegistry, elementFactory, canvas, m var replacements = context.canExecute.replace; - forEach(replacements, function(newElementData) { + forEach(replacements, function(replacement) { - var id = newElementData.id; + var id = replacement.oldElementId; var newElement = { - type: newElementData.type + type: replacement.newElementType }; // if the visual of the element is already replaced diff --git a/lib/features/replace/BpmnReplace.js b/lib/features/replace/BpmnReplace.js index 484acfe1..77353d8a 100644 --- a/lib/features/replace/BpmnReplace.js +++ b/lib/features/replace/BpmnReplace.js @@ -54,9 +54,12 @@ function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modelin * * @param {djs.model.Base} element * @param {Object} target + * @param {Object} [hints] * @return {djs.model.Base} the newly created element */ - function replaceElement(element, target) { + function replaceElement(element, target, hints) { + + hints = hints || {}; var type = target.type, oldBusinessObject = element.businessObject, @@ -103,7 +106,9 @@ function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modelin newElement = replace.replaceElement(element, newElement); - selection.select(newElement); + if (hints.select !== false) { + selection.select(newElement); + } return newElement; } diff --git a/test/spec/features/modeling/behavior/MoveStartEventBehaviorSpec.js b/test/spec/features/modeling/behavior/MoveStartEventBehaviorSpec.js index 5d195c5a..b977b040 100644 --- a/test/spec/features/modeling/behavior/MoveStartEventBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/MoveStartEventBehaviorSpec.js @@ -11,7 +11,7 @@ var replacePreviewModule = require('../../../../../lib/features/replace-preview' var is = require('../../../../../lib/util/ModelUtil').is, Events = require('diagram-js/test/util/Events'); -describe.only('features/modeling - move start event behavior', function() { +describe('features/modeling - move start event behavior', function() { var testModules = [ replacePreviewModule, modelingModule, coreModule ]; @@ -60,6 +60,36 @@ describe.only('features/modeling - move start event behavior', function() { // then expect(selection.get()).to.include(replacement); + expect(selection.get()).not.to.include(startEvent); + + })); + + + it('should select all moved shapes after some of them got replaced', + inject(function(elementRegistry, canvas, dragging, move, selection) { + + // given + var startEvent1 = elementRegistry.get('StartEvent_1'), + startEvent2 = elementRegistry.get('StartEvent_2'), + startEvent3 = elementRegistry.get('StartEvent_3'), + rootElement = canvas.getRootElement(); + + // when + selection.select([ startEvent1, startEvent2, startEvent3 ]); + moveShape(startEvent1, rootElement, { x: 140, y: 250 }); + + dragging.end(); + + var replacements = elementRegistry.filter(function(element) { + if(is(element, 'bpmn:StartEvent') && element.type !== 'label') { + return true; + } + }); + + // then + expect(selection.get()).to.include(replacements[0]); + expect(selection.get()).to.include(replacements[1]); + expect(selection.get()).to.include(replacements[2]); }));