Skip to content

Commit

Permalink
Merge pull request #2193 from milan-w/fix/duplicate-line-styles
Browse files Browse the repository at this point in the history
Resubmit: Fix duplication of line styles when inserting a newline in IText
  • Loading branch information
kangax committed May 13, 2015
2 parents d596089 + e5e15e4 commit 07445de
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@
var numericLine = parseInt(line, 10);
if (numericLine > lineIndex) {
this.styles[numericLine + offset] = clonedStyles[numericLine];
if (!clonedStyles[numericLine - offset]) {
delete this.styles[numericLine];
}
}
}
//TODO: evaluate if delete old style lines with offset -1
Expand Down
36 changes: 36 additions & 0 deletions test/unit/itext.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,42 @@
deepEqual(iText.styles, { '1': { '0': { } } });
});

test('shiftLineStyles', function() {
var iText = new fabric.IText('test\ntest\ntest', {
styles: {
'1': {
'0': { 'fill': 'red' },
'1': { 'fill': 'red' },
'2': { 'fill': 'red' },
'3': { 'fill': 'red' }
}
}
});

equal(typeof iText.shiftLineStyles, 'function');

iText.shiftLineStyles(0, +1);
deepEqual(iText.styles, {
'2': {
'0': { 'fill': 'red' },
'1': { 'fill': 'red' },
'2': { 'fill': 'red' },
'3': { 'fill': 'red' }
}
});

iText.shiftLineStyles(0, -1);
deepEqual(iText.styles, {
'1': {
'0': { 'fill': 'red' },
'1': { 'fill': 'red' },
'2': { 'fill': 'red' },
'3': { 'fill': 'red' }
}
});

});

test('selectWord', function() {
var iText = new fabric.IText('test foo bar-baz\nqux');

Expand Down

0 comments on commit 07445de

Please sign in to comment.