Skip to content

Commit

Permalink
fix(Object): ISSUE 6196 use set('canvas') to restore canvas (#6216)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Mar 15, 2020
1 parent 0d1f32a commit 4c126b4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/mixins/animation.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
propPair = property.split('.');
}

var propIsColor = _this.colorProperties.indexOf(property) > -1 || (propPair && _this.colorProperties.indexOf(propPair[1]) > -1);
var propIsColor =
_this.colorProperties.indexOf(property) > -1 ||
(propPair && _this.colorProperties.indexOf(propPair[1]) > -1);

var currentValue = propPair
? this.get(propPair[0])[propPair[1]]
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@
canvas.add(this);
var canvasEl = canvas.toCanvasElement(multiplier || 1, options);
this.shadow = originalShadow;
this.canvas = originalCanvas;
this.set('canvas', originalCanvas);
if (originalGroup) {
this.group = originalGroup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@
var markup = '', fontList = { }, obj, fontFamily,
style, row, rowIndex, _char, charIndex, i, len,
fontPaths = fabric.fontPaths, objects = [];

this._objects.forEach(function add(object) {
objects.push(object);
if (object._objects) {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,31 @@
assert.ok(typeof canvasEl.getContext === 'function', 'the element returned is a canvas');
});

QUnit.test('toCanvasElement activeSelection', function(assert) {
var cObj = new fabric.Rect({
width: 100, height: 100, fill: 'red', strokeWidth: 0
});

var cObj2 = new fabric.Rect({
width: 100, height: 100, fill: 'red', strokeWidth: 0
});

canvas.add(cObj, cObj2);

var activeSel = new fabric.ActiveSelection([cObj, cObj2], { canvas: canvas });

assert.equal(cObj.canvas, canvas, 'canvas is the main one step 1');

activeSel.toCanvasElement();

assert.equal(cObj.canvas, canvas, 'canvas is the main one step 2');

activeSel.destroy();

assert.equal(cObj.canvas, canvas, 'canvas is the main one step 3');

});

QUnit.test('toCanvasElement does not modify oCoords on zoomed canvas', function(assert) {
var cObj = new fabric.Rect({
width: 100, height: 100, fill: 'red', strokeWidth: 0
Expand Down

0 comments on commit 4c126b4

Please sign in to comment.