mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Change behavior of Path#fullySelected.
Setting it on empty paths does the same as Path#selected.
This commit is contained in:
parent
c2a34d9f1f
commit
3958d35f28
2 changed files with 21 additions and 17 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue