Skip to content

Commit

Permalink
object_stacking fix (#4394)
Browse files Browse the repository at this point in the history
* when calling moveTo on an activeSelection the code should move the objects in the canvas._objects stack instead of moveing the objects in the activeObject._objects stack. This already works correctly for moveForward / moveBack / ect.

* Update activeselection.js

* fix trailing spaces

* Update activeselection.js
  • Loading branch information
stefanhayden authored and asturur committed Oct 27, 2017
1 parent 40f16a9 commit 863eec4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mixins/object_stacking.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
* @chainable
*/
moveTo: function(index) {
if (this.group) {
if (this.group && this.group.type !== 'activeSelection') {
fabric.StaticCanvas.prototype.moveTo.call(this.group, this, index);
}
else {
Expand Down
37 changes: 37 additions & 0 deletions test/unit/activeselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,41 @@
assert.equal(g2._objects[3].canvas, canvas);
});

QUnit.test('moveTo on activeSelection', function(assert) {
var group = makeAsWith4Objects({ canvas: canvas }),
groupEl1 = group.getObjects()[0],
groupEl2 = group.getObjects()[1],
groupEl3 = group.getObjects()[2],
groupEl4 = group.getObjects()[3];
canvas.add(groupEl1, groupEl2, groupEl3, groupEl4);
canvas.setActiveObject(group);
assert.ok(typeof group.item(0).moveTo === 'function');

// [ 1, 2, 3, 4 ]
assert.equal(group.item(0), groupEl1, 'actual group position 1');
assert.equal(group.item(1), groupEl2, 'actual group position 2');
assert.equal(group.item(2), groupEl3, 'actual group position 3');
assert.equal(group.item(3), groupEl4, 'actual group position 4');
assert.equal(group.item(9999), undefined);
assert.equal(canvas.item(0), groupEl1, 'actual canvas position 1');
assert.equal(canvas.item(1), groupEl2, 'actual canvas position 2');
assert.equal(canvas.item(2), groupEl3, 'actual canvas position 3');
assert.equal(canvas.item(3), groupEl4, 'actual canvas position 4');
assert.equal(canvas.item(9999), undefined);

group.item(0).moveTo(3);

assert.equal(group.item(0), groupEl1, 'did not change group position 1');
assert.equal(group.item(1), groupEl2, 'did not change group position 2');
assert.equal(group.item(2), groupEl3, 'did not change group position 3');
assert.equal(group.item(3), groupEl4, 'did not change group position 4');
assert.equal(group.item(9999), undefined);
// moved 1 to level 3 — [2, 3, 4, 1]
assert.equal(canvas.item(3), groupEl1, 'item 1 is not at last');
assert.equal(canvas.item(0), groupEl2, 'item 2 shifted down to 1');
assert.equal(canvas.item(1), groupEl3, 'item 3 shifted down to 2');
assert.equal(canvas.item(2), groupEl4, 'item 4 shifted down to 3');
assert.equal(canvas.item(9999), undefined);
});

})();

0 comments on commit 863eec4

Please sign in to comment.