Skip to content

Commit

Permalink
ApplyFilters updates dirty flag in orde to refresh groups (#4828)
Browse files Browse the repository at this point in the history
* added dirty to apply filter

* applied to resize filter too

* applied to resize filter too

* fixed test

* fixed tests
  • Loading branch information
asturur authored Mar 17, 2018
1 parent 7698801 commit eb97ed5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@
scaleX = this.scaleX * retinaScaling,
scaleY = this.scaleY * retinaScaling,
elementToFilter = this._filteredEl || this._originalElement;
if (this.group) {
this.set('dirty', true);
}
if (!filter || (scaleX > minimumScale && scaleY > minimumScale)) {
this._element = elementToFilter;
this._filterScalingX = 1;
Expand Down Expand Up @@ -424,6 +427,9 @@

filters = filters || this.filters || [];
filters = filters.filter(function(filter) { return filter; });
if (this.group) {
this.set('dirty', true);
}
if (filters.length === 0) {
this._element = this._originalElement;
this._filteredEl = null;
Expand Down
26 changes: 26 additions & 0 deletions test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,30 @@
done();
});
});

QUnit.test('apply filters do not set the image dirty if not in group', function(assert) {
var done = assert.async();
createImageObject(function(image) {
image.dirty = false;
assert.equal(image.dirty, false, 'false apply filter dirty is false');
image.applyFilters();
assert.equal(image.dirty, false, 'After apply filter dirty is true');
done();
});
});

QUnit.test('apply filters set the image dirty and also the group', function(assert) {
var done = assert.async();
createImageObject(function(image) {
var group = new fabric.Group([image]);
image.dirty = false;
group.dirty = false;
assert.equal(image.dirty, false, 'false apply filter dirty is false');
assert.equal(group.dirty, false, 'false apply filter dirty is false');
image.applyFilters();
assert.equal(image.dirty, true, 'After apply filter dirty is true');
assert.equal(group.dirty, true, 'After apply filter dirty is true');
done();
});
});
})();

0 comments on commit eb97ed5

Please sign in to comment.