mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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) {
|
setSegments: function(segments) {
|
||||||
this._selectedSegmentState = 0;
|
var fullySelected = this.isFullySelected();
|
||||||
this._segments.length = 0;
|
this._segments.length = 0;
|
||||||
|
this._selectedSegmentState = 0;
|
||||||
// Calculate new curves next time we call getCurves()
|
// Calculate new curves next time we call getCurves()
|
||||||
delete this._curves;
|
delete this._curves;
|
||||||
this._add(Segment.readAll(segments));
|
this._add(Segment.readAll(segments));
|
||||||
|
if (fullySelected)
|
||||||
|
this.setFullySelected(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -324,8 +327,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
curves = this._curves,
|
curves = this._curves,
|
||||||
amount = segs.length,
|
amount = segs.length,
|
||||||
append = index == null,
|
append = index == null,
|
||||||
index = append ? segments.length : index,
|
index = append ? segments.length : index;
|
||||||
fullySelected = this.isFullySelected();
|
|
||||||
// Scan through segments to add first, convert if necessary and set
|
// Scan through segments to add first, convert if necessary and set
|
||||||
// _path and _index references on them.
|
// _path and _index references on them.
|
||||||
for (var i = 0; i < amount; i++) {
|
for (var i = 0; i < amount; i++) {
|
||||||
|
@ -336,9 +338,6 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
segment = segs[i] = segment.clone();
|
segment = segs[i] = segment.clone();
|
||||||
segment._path = this;
|
segment._path = this;
|
||||||
segment._index = index + i;
|
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
|
// If parts of this segment are selected, adjust the internal
|
||||||
// _selectedSegmentState now
|
// _selectedSegmentState now
|
||||||
if (segment._selectionState)
|
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
|
* @type Boolean
|
||||||
* @bean
|
* @bean
|
||||||
|
@ -780,8 +780,9 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
isFullySelected: function() {
|
isFullySelected: function() {
|
||||||
return this._selected && this._selectedSegmentState
|
var length = this._segments.length;
|
||||||
== this._segments.length * /*#=*/ SelectionState.POINT;
|
return this._selected && length > 0 && this._selectedSegmentState
|
||||||
|
=== length * /*#=*/ SelectionState.POINT;
|
||||||
},
|
},
|
||||||
|
|
||||||
setFullySelected: function(selected) {
|
setFullySelected: function(selected) {
|
||||||
|
|
|
@ -126,27 +126,29 @@ test('Is the path deselected after setting a new list of segments?', function()
|
||||||
}, 1);
|
}, 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();
|
var path = new Path();
|
||||||
path.fullySelected = true;
|
path.fullySelected = true;
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return path.fullySelected;
|
return path.fullySelected;
|
||||||
}, true);
|
}, false);
|
||||||
path.add([10, 10]);
|
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return path.fullySelected;
|
return path.selected;
|
||||||
}, true);
|
|
||||||
equals(function() {
|
|
||||||
return path.firstSegment.selected;
|
|
||||||
}, true);
|
}, 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]);
|
var path = new Path([10, 20], [30, 40]);
|
||||||
path.fullySelected = true;
|
path.fullySelected = true;
|
||||||
|
equals(function() {
|
||||||
|
return path.fullySelected;
|
||||||
|
}, true);
|
||||||
path.removeSegments();
|
path.removeSegments();
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return path.fullySelected;
|
return path.fullySelected;
|
||||||
|
}, false);
|
||||||
|
equals(function() {
|
||||||
|
return path.selected;
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -175,6 +177,7 @@ test('After simplifying a path using #simplify(), the path should stay fullySele
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return path.selected;
|
return path.selected;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return path.fullySelected;
|
return path.fullySelected;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
Loading…
Reference in a new issue