IE replace text selection with keypress (#3137)

Why:
* After creating a textbox, selecting text, and pressing a key, the first character of the previous text would remain.
* This happened because the hidden textarea would not update its selection in IE when it was in the same parent element as the canvas.
This change addresses the need by:

* Keeping the hidden textarea in the body element.
* IE now correctly updates the text selection as the user interacts with the canvas textbox.
This commit is contained in:
Scott Seaward 2016-08-01 16:46:40 -04:00 committed by Andrea Bogazzi
parent 9e4ed9565f
commit ebb2552357
2 changed files with 1 additions and 10 deletions

View file

@ -93,10 +93,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
this.__mousedownY = pointer.y;
this.__isMousedown = true;
if (this.hiddenTextarea && this.canvas) {
this.canvas.wrapperEl.appendChild(this.hiddenTextarea);
}
if (this.selected) {
this.setCursorByClick(options.e);
}

View file

@ -9,12 +9,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
var style = this._calcTextareaPosition();
this.hiddenTextarea.style.cssText = 'position: absolute; top: ' + style.top + '; left: ' + style.left + ';'
+ ' opacity: 0; width: 0px; height: 0px; z-index: -999;';
if (this.canvas) {
this.canvas.lowerCanvasEl.parentNode.appendChild(this.hiddenTextarea);
}
else {
fabric.document.body.appendChild(this.hiddenTextarea);
}
fabric.document.body.appendChild(this.hiddenTextarea);
fabric.util.addListener(this.hiddenTextarea, 'keydown', this.onKeyDown.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'keyup', this.onKeyUp.bind(this));