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
This commit is contained in:
Andrea Bogazzi 2015-09-27 16:37:32 +02:00
parent f46813499d
commit c943d369a2

View file

@ -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();
},
/**