diff --git a/build.js b/build.js index 27f83faa..04a51fed 100644 --- a/build.js +++ b/build.js @@ -247,7 +247,6 @@ var filesToInclude = [ ifSpecifiedInclude('textbox', 'src/shapes/textbox.class.js'), ifSpecifiedInclude('textbox', 'src/mixins/textbox_behavior.mixin.js'), ifSpecifiedInclude('textbox', 'src/mixins/textbox_click_behavior.mixin.js'), - ifSpecifiedInclude('textbox', 'src/mixins/textbox_key_behavior.mixin.js'), ifSpecifiedInclude('node', 'src/node.js'), diff --git a/src/mixins/textbox_key_behavior.mixin.js b/src/mixins/textbox_key_behavior.mixin.js deleted file mode 100644 index bab82dc5..00000000 --- a/src/mixins/textbox_key_behavior.mixin.js +++ /dev/null @@ -1,32 +0,0 @@ -fabric.util.object.extend(fabric.Textbox.prototype, /** @lends fabric.Textbox.prototype */ { - /** - * Overrides superclass function and adjusts cursor offset value because - * lines do not necessarily end with a newline in Textbox. - * - * @param {Event} e - * @param {Boolean} isRight - * @returns {Number} - */ - getDownCursorOffset: function (e, isRight) { - var current = this.selectionStart, - offset = fabric.IText.prototype.getDownCursorOffset.apply(this, [e, isRight]), - nextNewline = this.text.indexOf('\n', current); - - return nextNewline >= current && nextNewline <= current + offset ? offset : offset - 1; - }, - /** - * Overrides superclass function and adjusts cursor offset value because - * lines do not necessarily end with a newline in Textbox. - * - * @param {Event} e - * @param {Boolean} isRight - * @returns {Number} - */ - getUpCursorOffset: function (e, isRight) { - var current = this.selectionStart, - offset = fabric.IText.prototype.getUpCursorOffset.apply(this, [e, isRight]), - previousNewLine = this.text.indexOf('\n', current - offset); - - return previousNewLine >= current - offset && previousNewLine <= current ? offset : offset - 1; - } -}); diff --git a/src/shapes/textbox.class.js b/src/shapes/textbox.class.js index 0a977927..82605686 100644 --- a/src/shapes/textbox.class.js +++ b/src/shapes/textbox.class.js @@ -284,7 +284,7 @@ lineWidth = line === '' ? wordWidth : this._measureText(ctx, line + words[0], lineIndex, offset); if (Math.ceil(lineWidth) < maxWidth || (line === '' && Math.ceil(wordWidth) >= maxWidth)) { - line += words.shift() + ' '; + line += (line === '' ? '' : ' ') + words.shift(); } else { offset += line.length; @@ -293,7 +293,7 @@ } if (words.length === 0) { - lines.push(line.substring(0, line.length - 1)); + lines.push(line); } // keep track of largest word