Skip to content

Commit

Permalink
Fix text insert on null, give default style to text (#4166)
Browse files Browse the repository at this point in the history
* text style error
* change text init
* fixes
  • Loading branch information
asturur authored Aug 3, 2017
1 parent c705c6b commit 068c815
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,9 @@
* @param {Array} copiedStyle array of style objecs
*/
insertCharStyleObject: function(lineIndex, charIndex, quantity, copiedStyle) {

if (!this.styles) {
this.styles = {};
}
var currentLineStyles = this.styles[lineIndex],
currentLineStylesCloned = clone(currentLineStyles);

Expand All @@ -780,15 +782,15 @@
}
}
this._forceClearCache = true;
if (!currentLineStyles) {
return;
}
if (copiedStyle) {
while (quantity--) {
this.styles[lineIndex][charIndex + quantity] = clone(copiedStyle[quantity]);
}
return;
}
if (!currentLineStyles) {
return;
}
var newStyle = currentLineStyles[charIndex ? charIndex - 1 : 1];
while (newStyle && quantity--) {
this.styles[lineIndex][charIndex + quantity] = clone(newStyle);
Expand Down
3 changes: 1 addition & 2 deletions src/shapes/active_selection.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* @return {Object} thisArg
*/
initialize: function(objects, options) {
options = options || { };

options = options || {};
this._objects = objects || [];
for (var i = this._objects.length; i--; ) {
this._objects[i].group = this;
Expand Down
3 changes: 1 addition & 2 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
* @return {Object} thisArg
*/
initialize: function(objects, options, isAlreadyGrouped) {
options = options || { };

options = options || {};
this._objects = [];
// if objects enclosed in a group have been grouped already,
// we cannot change properties of objects.
Expand Down
1 change: 0 additions & 1 deletion src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
* @return {fabric.IText} thisArg
*/
initialize: function(text, options) {
this.styles = options ? (options.styles || { }) : { };
this.callSuper('initialize', text, options);
this.initBehavior();
},
Expand Down
1 change: 0 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@
* @param {Object} [options] Options object
*/
initialize: function(options) {
options = options || { };
if (options) {
this.setOptions(options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
* @return {fabric.Text} thisArg
*/
initialize: function(text, options) {
options = options || { };
this.styles = options ? (options.styles || { }) : { };
this.text = text;
this.__skipDimension = true;
this.callSuper('initialize', options);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'skewY': 0,
'transformMatrix': null,
'charSpacing': 0,
'styles': null
'styles': {}
};

var TEXT_SVG = '\t<g transform="translate(10.5 26.72)">\n\t\t<text xml:space="preserve" font-family="Times New Roman" font-size="40" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" >\n\t\t\t<tspan x="-10" y="12.57" >x</tspan>\n\t\t</text>\n\t</g>\n';
Expand Down

0 comments on commit 068c815

Please sign in to comment.