diff --git a/lib/features/modeling/rules/ModelingRules.js b/lib/features/modeling/rules/ModelingRules.js index 164f7fa8..65ef1e2e 100644 --- a/lib/features/modeling/rules/ModelingRules.js +++ b/lib/features/modeling/rules/ModelingRules.js @@ -17,31 +17,40 @@ ModelingRules.prototype = Object.create(RuleProvider.prototype); ModelingRules.prototype.init = function() { + function nonExistantOrLabel(element) { + return !element || element.labelTarget; + } + + function isSame(a, b) { + return a === b; + } + // rules function canConnect(source, target, connection) { - if (!source || source.labelTarget || !target || target.labelTarget) { + if (nonExistantOrLabel(source) || nonExistantOrLabel(target)) { return null; } - var sourceBo = source.businessObject, - targetBo = target.businessObject, - connectionBo = connection && connection.businessObject; - - if (sourceBo.$parent !== targetBo.$parent) { - return false; - } - // See https://github.com/bpmn-io/bpmn-js/issues/178 // as a workround we disallow connections with same // target and source element. // This rule must be removed if a auto layout for this // connections is implemented. - if (sourceBo === targetBo) { + if (isSame(source, target)) { return false; } + // only move between the same parent + if (!isSame(source.parent, target.parent)) { + return false; + } + + var sourceBo = source.businessObject, + targetBo = target.businessObject, + connectionBo = connection && connection.businessObject; + if (connectionBo && connectionBo.$instanceOf('bpmn:SequenceFlow')) { if (!sourceBo.$instanceOf('bpmn:FlowNode') || @@ -165,7 +174,7 @@ ModelingRules.prototype.init = function() { // into source var t = target; while (t) { - if (t === source) { + if (isSame(t, source)) { return false; }