Skip to content

Commit

Permalink
fix setSelectionStyles do not set anything when there is no selection (
Browse files Browse the repository at this point in the history
…#3765)

* fix setSelection
* fixed tests
  • Loading branch information
asturur authored Mar 6, 2017
1 parent 50180a1 commit efcd946
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit efcd946

Please sign in to comment.