Pass Item.NO_INSERT to internally created paths and do not rely on insertAbove() to always return a result.

If `this` itself is not in the DOM, insertAbove() will fail.
This commit is contained in:
Jürg Lehni 2015-10-24 17:45:22 +02:00
parent 1fc17766fb
commit fcd4fe824c
2 changed files with 6 additions and 3 deletions

View file

@ -334,7 +334,8 @@ new function() { // Injection scope for PostScript-like drawing functions
moveTo: function(/* point */) {
var current = getCurrentPath(this),
// Reuse current path if nothing was added yet
path = current && current.isEmpty() ? current : new Path();
path = current && current.isEmpty() ? current
: new Path(Item.NO_INSERT);
if (path !== current)
this.addChild(path);
path.moveTo.apply(path, arguments);

View file

@ -1241,10 +1241,12 @@ var Path = PathItem.extend(/** @lends Path# */{
// will happen below.
path = this;
} else {
path = new Path(Item.NO_INSERT);
// Pass true for _preserve, in case of CompoundPath, to avoid
// reversing of path direction, which would mess with segs!
// reversing of path direction, which would mess with segments!
path.insertAbove(this, true);
// Use _clone to copy over all other attributes, including style
path = this._clone(new Path().insertAbove(this, true));
this._clone(path);
}
path._add(segs, 0);
// Add dividing segment again. In case of a closed path, that's the