From 3958d35f288fd675327b25e1090e60a9f4cf4916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 17 Oct 2013 12:03:46 +0200 Subject: [PATCH] Change behavior of Path#fullySelected. Setting it on empty paths does the same as Path#selected. --- src/path/Path.js | 19 ++++++++++--------- test/tests/Path.js | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index e971a2ce..7c85d6fa 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -138,11 +138,14 @@ var Path = PathItem.extend(/** @lends Path# */{ }, setSegments: function(segments) { - this._selectedSegmentState = 0; + var fullySelected = this.isFullySelected(); this._segments.length = 0; + this._selectedSegmentState = 0; // Calculate new curves next time we call getCurves() delete this._curves; this._add(Segment.readAll(segments)); + if (fullySelected) + this.setFullySelected(true); }, /** @@ -324,8 +327,7 @@ var Path = PathItem.extend(/** @lends Path# */{ curves = this._curves, amount = segs.length, append = index == null, - index = append ? segments.length : index, - fullySelected = this.isFullySelected(); + index = append ? segments.length : index; // Scan through segments to add first, convert if necessary and set // _path and _index references on them. for (var i = 0; i < amount; i++) { @@ -336,9 +338,6 @@ var Path = PathItem.extend(/** @lends Path# */{ segment = segs[i] = segment.clone(); segment._path = this; segment._index = index + i; - // Select newly added segments if path was fully selected before - if (fullySelected) - segment._selectionState = /*#=*/ SelectionState.POINT; // If parts of this segment are selected, adjust the internal // _selectedSegmentState now if (segment._selectionState) @@ -745,7 +744,8 @@ var Path = PathItem.extend(/** @lends Path# */{ * */ /** - * Specifies whether the path and all its segments are selected. + * Specifies whether the path and all its segments are selected. Cannot be + * {@code true} on an empty path. * * @type Boolean * @bean @@ -780,8 +780,9 @@ var Path = PathItem.extend(/** @lends Path# */{ * } */ isFullySelected: function() { - return this._selected && this._selectedSegmentState - == this._segments.length * /*#=*/ SelectionState.POINT; + var length = this._segments.length; + return this._selected && length > 0 && this._selectedSegmentState + === length * /*#=*/ SelectionState.POINT; }, setFullySelected: function(selected) { diff --git a/test/tests/Path.js b/test/tests/Path.js index 958bfd84..299b817a 100644 --- a/test/tests/Path.js +++ b/test/tests/Path.js @@ -126,27 +126,29 @@ test('Is the path deselected after setting a new list of segments?', function() }, 1); }); -test('After setting Path#fullySelected=true on an empty path, subsequent segments should be selected', function() { +test('Setting Path#fullySelected=true on an empty path should only set path#selected=true', function() { var path = new Path(); path.fullySelected = true; equals(function() { return path.fullySelected; - }, true); - path.add([10, 10]); + }, false); equals(function() { - return path.fullySelected; - }, true); - equals(function() { - return path.firstSegment.selected; + return path.selected; }, true); }); -test('After removing all segments of a fully selected path, it should still be fully selected.', function() { +test('After removing all segments of a fully selected path, it should still be selected.', function() { var path = new Path([10, 20], [30, 40]); path.fullySelected = true; + equals(function() { + return path.fullySelected; + }, true); path.removeSegments(); equals(function() { return path.fullySelected; + }, false); + equals(function() { + return path.selected; }, true); }); @@ -175,6 +177,7 @@ test('After simplifying a path using #simplify(), the path should stay fullySele equals(function() { return path.selected; }, true); + equals(function() { return path.fullySelected; }, true);