diff --git a/lib/features/modeling/behavior/DropOnFlowBehavior.js b/lib/features/modeling/behavior/DropOnFlowBehavior.js index 28dcf38f..a928d5ea 100644 --- a/lib/features/modeling/behavior/DropOnFlowBehavior.js +++ b/lib/features/modeling/behavior/DropOnFlowBehavior.js @@ -50,6 +50,11 @@ function DropOnFlow(eventBus, bpmnRules, modeling) { waypointsBefore = waypoints.slice(0, intersection.index); waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0)); + // due to inaccuracy intersection might have been found + if (!waypointsBefore.length || !waypointsAfter.length) { + return; + } + dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : position; // if last waypointBefore is inside shape's bounds, ignore docking point @@ -161,4 +166,4 @@ inherits(DropOnFlow, CommandInterceptor); DropOnFlow.$inject = [ 'eventBus', 'bpmnRules', 'modeling' ]; -module.exports = DropOnFlow; +module.exports = DropOnFlow; \ No newline at end of file diff --git a/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js b/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js index 33607977..4162ab4e 100644 --- a/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js @@ -22,21 +22,6 @@ describe('modeling/behavior - drop on connection', function() { beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); - describe('rules', function() { - - it('should be allowed for an IntermediateThrowEvent', inject(function(elementRegistry, bpmnRules, elementFactory) { - - // when - var sequenceFlow = elementRegistry.get('SequenceFlow_1'); - var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' }); - - // then - expect(bpmnRules.canCreate(intermediateThrowEvent, sequenceFlow)).to.be.true; - })); - - }); - - describe('execution', function() { describe('create', function() { @@ -512,6 +497,34 @@ describe('modeling/behavior - drop on connection', function() { } )); + + it('should not insert on inaccuratly found intersection', inject(function(dragging, move, elementRegistry, selection) { + + // given + var intermediateThrowEvent = elementRegistry.get('IntermediateThrowEvent_foo'); + + var sequenceFlow = elementRegistry.get('SequenceFlow_1'), + sequenceFlowGfx = elementRegistry.getGraphics(sequenceFlow); + + // when + selection.select(intermediateThrowEvent); + + move.start(canvasEvent({ x: 0, y: 0 }), intermediateThrowEvent); + + dragging.hover({ + element: sequenceFlow, + gfx: sequenceFlowGfx + }); + + dragging.move(canvasEvent({ x: 20, y: -90 })); + + dragging.end(); + + // then + expect(intermediateThrowEvent.incoming).to.have.lengthOf(0); + expect(intermediateThrowEvent.outgoing).to.have.lengthOf(0); + })); + }); }); @@ -519,6 +532,17 @@ describe('modeling/behavior - drop on connection', function() { describe('rules', function() { + it('should be allowed for an IntermediateThrowEvent', inject(function(elementRegistry, bpmnRules, elementFactory) { + + // when + var sequenceFlow = elementRegistry.get('SequenceFlow_1'); + var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' }); + + // then + expect(bpmnRules.canCreate(intermediateThrowEvent, sequenceFlow)).to.be.true; + })); + + it('should not insert participant', inject( function(rules, elementRegistry, elementFactory) {