diff --git a/src/path/Path.js b/src/path/Path.js index d07faa2b..e8e8dfc7 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -414,8 +414,11 @@ var Path = PathItem.extend(/** @lends Path# */{ // Keep the curves list in sync all the time in case it was requested // already. if (curves) { - var start = from, - to = Math.min(from + amount, this._countCurves()); + var total = this._countCurves(), + // If we're adding a new segment to the end of an open path, + // we need to step one index down to get its curve. + start = from === total ? from - 1 : from, + to = Math.min(from + amount, total); if (segs._curves) { // Reuse removed curves. curves.splice.apply(curves, [from, 0].concat(segs._curves)); diff --git a/test/tests/Path_Curves.js b/test/tests/Path_Curves.js index e8d9b640..9f06179f 100644 --- a/test/tests/Path_Curves.js +++ b/test/tests/Path_Curves.js @@ -100,11 +100,17 @@ test('Curve list after removing a segment - 2', function() { equals(function() { return path.segments[2].remove(); - }, true, 'Removing the paths last segment should be succesfull.'); + }, true, 'Removing the paths last segment should be successful.'); equals(function() { return path.curves.length; }, 1, 'After removing the last segment, we should be left with one curve'); + + path.addSegment([4, 4]); + + equals(function() { + return path.curves.length; + }, 2, 'After adding a new segment at the end, we should have two curves again'); }); test('Splitting a straight path should produce segments without handles', function() {