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

Resubmit: Fix duplication of line styles when inserting a newline in IText #2193

Merged
merged 4 commits into from
May 13, 2015
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
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