diff --git a/src/mixins/textbox_behavior.mixin.js b/src/mixins/textbox_behavior.mixin.js index bc87ed93..65d053fc 100644 --- a/src/mixins/textbox_behavior.mixin.js +++ b/src/mixins/textbox_behavior.mixin.js @@ -45,7 +45,7 @@ /** * @private */ - _removeExtraneousStyles: function() { + _removeExtraneousStyles: function () { //for (var prop in this._styleMap) { // if (!this._textLines[prop]) { // delete this.styles[this._styleMap[prop].line]; @@ -59,7 +59,7 @@ * @param {Number} charIndex Index of a char * @param {Object} [style] Style object to insert, if given */ - insertCharStyleObject: function(lineIndex, charIndex, style) { + insertCharStyleObject: function (lineIndex, charIndex, style) { // adjust lineIndex and charIndex var map = this._styleMap[lineIndex]; lineIndex = map.line; @@ -74,7 +74,7 @@ * @param {Number} charIndex Index of a char * @param {Boolean} isEndOfLine True if it's end of line */ - insertNewlineStyleObject: function(lineIndex, charIndex, isEndOfLine) { + insertNewlineStyleObject: function (lineIndex, charIndex, isEndOfLine) { // adjust lineIndex and charIndex var map = this._styleMap[lineIndex]; lineIndex = map.line; @@ -90,7 +90,7 @@ * @param {Number} lineIndex Index of a line * @param {Number} offset Can be -1 or +1 */ - shiftLineStyles: function(lineIndex, offset) { + shiftLineStyles: function (lineIndex, offset) { // shift all line styles by 1 upward var clonedStyles = clone(this.styles); @@ -119,10 +119,10 @@ * @returns {String} * @private */ - _getTextOnPreviousLine: function(lineIndex) { + _getTextOnPreviousLine: function (lineIndex) { var textOnPreviousLine = this._textLines[lineIndex - 1]; - while(this._styleMap[lineIndex - 2] && this._styleMap[lineIndex - 2].line === this._styleMap[lineIndex - 1].line) { + while (this._styleMap[lineIndex - 2] && this._styleMap[lineIndex - 2].line === this._styleMap[lineIndex - 1].line) { textOnPreviousLine = this._textLines[lineIndex - 2] + textOnPreviousLine; lineIndex--; @@ -136,7 +136,7 @@ * @param {Boolean} isBeginningOfLine True if cursor is at the beginning of line * @param {Number} [index] Optional index. When not given, current selectionStart is used. */ - removeStyleObject: function(isBeginningOfLine, index) { + removeStyleObject: function (isBeginningOfLine, index) { var cursorLocation = this.get2DCursorLocation(index), map = this._styleMap[cursorLocation.lineIndex], @@ -148,7 +148,7 @@ newCharIndexOnPrevLine = textOnPreviousLine ? textOnPreviousLine.length : 0; if (!this.styles[lineIndex - 1]) { - this.styles[lineIndex - 1] = { }; + this.styles[lineIndex - 1] = {}; } for (charIndex in this.styles[lineIndex]) { diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js index 16803da8..48afcc7b 100644 --- a/src/shapes/itext.class.js +++ b/src/shapes/itext.class.js @@ -259,8 +259,9 @@ return styles; } - var loc = this.get2DCursorLocation(startIndex); - var style = this._getStyleDeclaration(loc.lineIndex, loc.charIndex); + var loc = this.get2DCursorLocation(startIndex), + style = this._getStyleDeclaration(loc.lineIndex, loc.charIndex); + return style || {}; }, @@ -917,7 +918,7 @@ * @private */ _getStyleDeclaration: function(lineIndex, charIndex, returnCloneOrEmpty) { - if(returnCloneOrEmpty) { + if (returnCloneOrEmpty) { return (this.styles[lineIndex] && this.styles[lineIndex][charIndex]) ? clone(this.styles[lineIndex][charIndex]) : { }; diff --git a/src/shapes/textbox.class.js b/src/shapes/textbox.class.js index 12a6646d..b402e2db 100644 --- a/src/shapes/textbox.class.js +++ b/src/shapes/textbox.class.js @@ -76,19 +76,19 @@ }, _generateStyleMap: function() { - var realLineCount = 0; - var realLineCharCount = 0; - var charCount = 0; - var map = {}; + var realLineCount = 0, + realLineCharCount = 0, + charCount = 0, + map = {}; - for(var i = 0; i < this._textLines.length; i++) { - if(this.text[charCount] === '\n') { + for (var i = 0; i < this._textLines.length; i++) { + if (this.text[charCount] === '\n') { realLineCharCount = 0; charCount++; realLineCount++; } - map[i] = {line: realLineCount, offset: realLineCharCount}; + map[i] = { line: realLineCount, offset: realLineCharCount }; charCount += this._textLines[i].length; realLineCharCount += this._textLines[i].length;