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

fix setSelectionStyles do not set anything when there is no selection #3765

Merged
merged 3 commits into from
Mar 6, 2017
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
4 changes: 2 additions & 2 deletions src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@
},

/**
* Sets style of a current selection
* Sets style of a current selection, if no selection exist, do not set anything.
* @param {Object} [styles] Styles object
* @return {fabric.IText} thisArg
* @chainable
*/
setSelectionStyles: function(styles) {
if (this.selectionStart === this.selectionEnd) {
this._extendStyles(this.selectionStart, styles);
return this;
}
else {
for (var i = this.selectionStart; i < this.selectionEnd; i++) {
Expand Down
13 changes: 12 additions & 1 deletion test/unit/itext.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,24 @@
stroke: 'yellow'
});

deepEqual(iText.styles[0][0], {
fill: '#112233'
});

iText.selectionEnd = 0;
iText.selectionEnd = 1;
iText.setSelectionStyles({
fill: 'red',
stroke: 'yellow'
});

deepEqual(iText.styles[0][0], {
fill: 'red',
stroke: 'yellow'
});

iText.selectionStart = 2;
iText.selectionEnd = 2;
iText.selectionEnd = 3;

iText.setSelectionStyles({
fill: '#998877',
Expand Down