Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanStyle bug #4751

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mixins/text_style.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
style = obj[p1][p2][property];
foundStyle = true;
}
else if (obj[p1][p2][property] !== style) {
else if (obj[p1][p2][property] !== style || !obj[p1][p2].hasOwnProperty(property)) {
canBeSwapped = false;
}
if (obj[p1][p2][property] === this[property]) {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,26 @@
assert.equal(text.styles[1][0].stroke, 'blue', 'nothing to clean, style untouched');
});

QUnit.test('text cleanStyle with different sub styles styles', function(assert) {
var text = new fabric.Text('xxxxxx\nx y');
text.styles = { 1: { 0: { fill: 'red' }, 1: { stroke: 'red' }}};
text.stroke = 'red';
text.cleanStyle('stroke');
assert.equal(text.stroke, 'red', 'the stroke stays red');
assert.equal(text.styles[1][0].fill, 'red', 'the style has not been changed since it\'s a different property');
assert.equal(text.styles[1][0].stroke, undefined, 'the style has been cleaned since stroke was equal to text property');
assert.equal(text.styles[1][1], undefined, 'the style remains undefined');
});

QUnit.test('text cleanStyle with undefined and set styles', function(assert) {
var text = new fabric.Text('xxxxxx\nx y');
text.styles = { 1: { 1: { stroke: 'red' }, 3: { stroke: 'red' }}};
text.stroke = 'red';
text.cleanStyle('stroke');
assert.equal(text.stroke, 'red', 'the stroke stays red');
assert.equal(text.styles[1], undefined, 'the style has been cleaned since stroke was equal to text property');
});

QUnit.test('text cleanStyle with empty styles', function(assert) {
var text = new fabric.Text('xxxxxx\nx y');
text.styles = { 1: { 0: { }, 1: { }}, 2: { }, 3: { 4: { }}};
Expand All @@ -354,6 +374,20 @@
assert.equal(text.styles[0], undefined, 'all the style has been removed');
});

QUnit.test('text cleanStyle with no relevant style', function(assert) {
var text = new fabric.Text('xxx');
text.styles = { 0: { 0: { other: 'value1' }, 1: { other: 'value2' }, 2: { other: 'value3' }}};
text.fill = 'black';
text.cleanStyle('fill');
assert.equal(text.fill, 'black', 'the fill remains black');
assert.equal(text.styles[0][0].other, 'value1', 'style remains the same');
assert.equal(text.styles[0][0].full, undefined, 'style remains undefined');
assert.equal(text.styles[0][1].other, 'value2', 'style remains the same');
assert.equal(text.styles[0][1].full, undefined, 'style remains undefined');
assert.equal(text.styles[0][2].other, 'value3', 'style remains the same');
assert.equal(text.styles[0][2].full, undefined, 'style remains undefined');
});

QUnit.test('text removeStyle with some style', function(assert) {
var text = new fabric.Text('xxx');
text.styles = { 0: { 0: { stroke: 'black', fill: 'blue' }, 1: { fill: 'blue' }, 2: { fill: 'blue' }}};
Expand Down