diff --git a/src/path/Path.js b/src/path/Path.js index ac6abc54..71fcc4ab 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -86,7 +86,7 @@ var Path = this.Path = PathItem.extend({ if (!this._segments) { this._segments = []; } else { - this.setSelected(false); + this._selectedSegmentState = 0; this._segments.length = 0; // Make sure new curves are calculated next time we call getCurves() if (this._curves) @@ -644,8 +644,12 @@ var Path = this.Path = PathItem.extend({ _updateSelection: function(segment, oldState, newState) { segment._selectionState = newState; - this.setSelected( - (this._selectedSegmentState += newState - oldState) > 0); + var total = this._selectedSegmentState += newState - oldState; + // Set this path as selected in case we have selected segments. Do not + // unselect if we're down to 0, as the path itself can still remain + // selected even when empty. + if (total > 0) + this.setSelected(true); }, /** diff --git a/test/tests/Path.js b/test/tests/Path.js index 624753d0..69e37ca2 100644 --- a/test/tests/Path.js +++ b/test/tests/Path.js @@ -108,10 +108,10 @@ test('Is the path deselected after setting a new list of segments?', function() path.segments = [[0, 10]]; equals(function() { return path.selected; - }, false); + }, true); equals(function() { return paper.project.selectedItems.length; - }, 0); + }, 1); }); test('After setting Path#fullySelected=true on an empty path, subsequent segments should be selected', function() { @@ -154,7 +154,15 @@ test('After simplifying a path using #simplify(), the path should stay fullySele path.add(i * 10, 10); }; path.fullySelected = true; + equals(function() { + return path.selected; + }, true); + path.simplify(); + + equals(function() { + return path.selected; + }, true); equals(function() { return path.fullySelected; }, true);