From c943d369a270f22b2934efd13e46d548b66882e3 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 27 Sep 2015 16:37:32 +0200 Subject: [PATCH 1/6] Update itext_key_behavior.mixin.js Remove cancelOnInput logic, a normal e.preventDefault + stopPropagation is enough. Take in account already selected text when deciding how much text we are inserting during input event --- src/mixins/itext_key_behavior.mixin.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mixins/itext_key_behavior.mixin.js b/src/mixins/itext_key_behavior.mixin.js index e5d33fc616f..cb4a4ce3781 100644 --- a/src/mixins/itext_key_behavior.mixin.js +++ b/src/mixins/itext_key_behavior.mixin.js @@ -81,14 +81,14 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot * @param {Event} e Event object */ onInput: function(e) { - if (!this.isEditing || this._cancelOnInput) { - this._cancelOnInput = false; + if (!this.isEditing) { return; } var offset = this.selectionStart || 0, + offsetEnd = this.selectionEnd || 0, textLength = this.text.length, newTextLength = this.hiddenTextarea.value.length, - diff = newTextLength - textLength, + diff = newTextLength - textLength + offsetEnd - offset, charsToInsert = this.hiddenTextarea.value.slice(offset, offset + diff); this.insertChars(charsToInsert); e.stopPropagation(); @@ -149,7 +149,8 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot if (copiedText) { this.insertChars(copiedText, useCopiedStyle); } - this._cancelOnInput = true; + e.stopImmediatePropagation(); + e.preventDefault(); }, /** From 49b876a7046603280f179834dbe9798a7d0b97ea Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 27 Sep 2015 16:58:15 +0200 Subject: [PATCH 2/6] Update textbox_behavior.mixin.js --- src/mixins/textbox_behavior.mixin.js | 37 +--------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/mixins/textbox_behavior.mixin.js b/src/mixins/textbox_behavior.mixin.js index 2b9d934bcb9..e8d8bc61769 100644 --- a/src/mixins/textbox_behavior.mixin.js +++ b/src/mixins/textbox_behavior.mixin.js @@ -142,42 +142,7 @@ map = this._styleMap[cursorLocation.lineIndex], lineIndex = map.line, charIndex = map.offset + cursorLocation.charIndex; - - if (isBeginningOfLine) { - var textOnPreviousLine = this._getTextOnPreviousLine(cursorLocation.lineIndex), - newCharIndexOnPrevLine = textOnPreviousLine ? textOnPreviousLine.length : 0; - - if (!this.styles[lineIndex - 1]) { - this.styles[lineIndex - 1] = {}; - } - - for (charIndex in this.styles[lineIndex]) { - this.styles[lineIndex - 1][parseInt(charIndex, 10) + newCharIndexOnPrevLine] - = this.styles[lineIndex][charIndex]; - } - - this.shiftLineStyles(cursorLocation.lineIndex, -1); - - } - else { - var currentLineStyles = this.styles[lineIndex]; - - if (currentLineStyles) { - delete currentLineStyles[charIndex]; - //console.log('deleting', lineIndex, charIndex + offset); - } - - var currentLineStylesCloned = clone(currentLineStyles); - - // shift all styles by 1 backwards - for (var i in currentLineStylesCloned) { - var numericIndex = parseInt(i, 10); - if (numericIndex >= charIndex && numericIndex !== 0) { - currentLineStyles[numericIndex - 1] = currentLineStylesCloned[numericIndex]; - delete currentLineStyles[numericIndex]; - } - } - } + this._removeStyleObject(isBeginningOfLine, cursorLocation, lineIndex, charIndex); } }); })(); From b020b243e912024d7ff155edc16682327859a15c Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 27 Sep 2015 17:00:16 +0200 Subject: [PATCH 3/6] removed some duplicate code --- src/mixins/itext_behavior.mixin.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mixins/itext_behavior.mixin.js b/src/mixins/itext_behavior.mixin.js index 1e790760ffb..44b9870fb37 100644 --- a/src/mixins/itext_behavior.mixin.js +++ b/src/mixins/itext_behavior.mixin.js @@ -703,35 +703,35 @@ lineIndex = cursorLocation.lineIndex, charIndex = cursorLocation.charIndex; - if (isBeginningOfLine) { + this._removeStyleObject(isBeginningOfLine, cursorLocation, lineIndex, charIndex); + }, + + _getTextOnPreviousLine: function(lIndex) { + return this._textLines[lIndex - 1]; + }, + + _removeStyleObject: function(isBeginningOfLine, cursorLocation, lineIndex, charIndex) { - var textOnPreviousLine = this._textLines[lineIndex - 1], - newCharIndexOnPrevLine = textOnPreviousLine - ? textOnPreviousLine.length - : 0; + if (isBeginningOfLine) { + var textOnPreviousLine = this._getTextOnPreviousLine(cursorLocation.lineIndex), + newCharIndexOnPrevLine = textOnPreviousLine ? textOnPreviousLine.length : 0; if (!this.styles[lineIndex - 1]) { this.styles[lineIndex - 1] = {}; } - for (charIndex in this.styles[lineIndex]) { this.styles[lineIndex - 1][parseInt(charIndex, 10) + newCharIndexOnPrevLine] = this.styles[lineIndex][charIndex]; } - - this.shiftLineStyles(lineIndex, -1); - + this.shiftLineStyles(cursorLocation.lineIndex, -1); } else { var currentLineStyles = this.styles[lineIndex]; if (currentLineStyles) { delete currentLineStyles[charIndex]; - //console.log('deleting', lineIndex, charIndex + offset); } - var currentLineStylesCloned = clone(currentLineStyles); - // shift all styles by 1 backwards for (var i in currentLineStylesCloned) { var numericIndex = parseInt(i, 10); From d026c3f30838ddaef3205b1ad0a2c53e41fa3f70 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 5 Oct 2015 15:13:31 +0200 Subject: [PATCH 4/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e77013ea368..62cb06ee48e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "canvas": "1.2.x", - "jsdom": "1.1.x", + "jsdom": "7.x.x", "xmldom": "0.1.x" }, "devDependencies": { From 21ed812c3e1d38a29edb77c11a0be84bb5b76707 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 5 Oct 2015 15:26:10 +0200 Subject: [PATCH 5/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 62cb06ee48e..90f3440b713 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "canvas": "1.2.x", - "jsdom": "7.x.x", + "jsdom": "6.x.x", "xmldom": "0.1.x" }, "devDependencies": { From c75756d7684ff87c113121bfb5840c8fcc3deaeb Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 5 Oct 2015 15:39:33 +0200 Subject: [PATCH 6/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90f3440b713..e77013ea368 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "canvas": "1.2.x", - "jsdom": "6.x.x", + "jsdom": "1.1.x", "xmldom": "0.1.x" }, "devDependencies": {