diff --git a/src/js/parser/javascript/regexp.js b/src/js/parser/javascript/regexp.js index 6a6e4a9..e265b80 100644 --- a/src/js/parser/javascript/regexp.js +++ b/src/js/parser/javascript/regexp.js @@ -29,35 +29,7 @@ export default _.extend({}, Base, { }); containerBox = this.getBBox(); - paths = _.map(matches, match => { - var box = match.getBBox(), - direction = box.cy > containerBox.cy ? 1 : -1, - distance = Math.abs(box.cy - containerBox.cy), - pathStr; - - if (distance >= 15) { - pathStr = [ - 'M10,{box.cy}m0,{shift}q0,{curve} 10,{curve}', - 'M{containerBox.width},{box.cy}m30,{shift}q0,{curve} -10,{curve}' - ].join(''); - } else { - pathStr = [ - 'M0,{containerBox.cy}c10,0 10,{anchor.y} 20,{anchor.y}', - 'M{containerBox.width},{containerBox.cy}m40,0c-10,0 -10,{anchor.y} -20,{anchor.y}' - ].join(''); - } - - return Snap.format(pathStr, { - containerBox, - box, - shift: -10 * direction, - curve: 10 * direction, - anchor: { - x: box.x + 20, - y: box.cy - containerBox.cy - } - }); - }); + paths = _.map(matches, this.makeConnectorLine.bind(this, containerBox)); paths.push(Snap.format([ 'M0,{box.cy}q10,0 10,-10V{top}', @@ -76,6 +48,36 @@ export default _.extend({}, Base, { } }, + makeConnectorLine(containerBox, match) { + var box = match.getBBox(), + direction = box.cy > containerBox.cy ? 1 : -1, + distance = Math.abs(box.cy - containerBox.cy), + pathStr; + + if (distance >= 15) { + pathStr = [ + 'M10,{box.cy}m0,{shift}q0,{curve} 10,{curve}', + 'M{containerBox.width},{box.cy}m30,{shift}q0,{curve} -10,{curve}' + ].join(''); + } else { + pathStr = [ + 'M0,{containerBox.cy}c10,0 10,{anchor.y} 20,{anchor.y}', + 'M{containerBox.width},{containerBox.cy}m40,0c-10,0 -10,{anchor.y} -20,{anchor.y}' + ].join(''); + } + + return Snap.format(pathStr, { + containerBox, + box, + shift: -10 * direction, + curve: 10 * direction, + anchor: { + x: box.x + 20, + y: box.cy - containerBox.cy + } + }); + }, + matches() { return [this._match].concat(_.map(this._alternates.elements, _.property('match'))); }