Allow user to select text moving mouse outside itext bounding box

This commit is contained in:
Andrea Bogazzi 2015-03-01 22:55:45 +01:00 committed by asturur
parent 4ad253ffba
commit dda96f9b81
2 changed files with 21 additions and 26 deletions

View file

@ -341,10 +341,28 @@
this._setEditingProps();
this._tick();
this.canvas && this.canvas.renderAll();
this.fire('editing:entered');
this.canvas && this.canvas.fire('text:editing:entered', { target: this });
if (this.canvas) {
var _this = this;
this.canvas.renderAll();
this.canvas.fire('text:editing:entered', { target: this });
this.canvas.on('mouse:move', function(options) {
if (!_this.__isMousedown || !_this.isEditing) {
return;
}
var newSelectionStart = _this.getSelectionStartFromPointer(options.e);
if (newSelectionStart >= _this.__selectionStartOnMouseDown) {
_this.setSelectionStart(_this.__selectionStartOnMouseDown);
_this.setSelectionEnd(newSelectionStart);
}
else {
_this.setSelectionStart(newSelectionStart);
_this.setSelectionEnd(_this.__selectionStartOnMouseDown);
}
});
}
return this;
},

View file

@ -63,7 +63,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
initCursorSelectionHandlers: function() {
this.initSelectedHandler();
this.initMousedownHandler();
this.initMousemoveHandler();
this.initMouseupHandler();
this.initClicks();
},
@ -107,28 +106,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
});
},
/**
* Initializes "mousemove" event handler
*/
initMousemoveHandler: function() {
this.on('mousemove', function(options) {
if (!this.__isMousedown || !this.isEditing) {
return;
}
var newSelectionStart = this.getSelectionStartFromPointer(options.e);
if (newSelectionStart >= this.__selectionStartOnMouseDown) {
this.setSelectionStart(this.__selectionStartOnMouseDown);
this.setSelectionEnd(newSelectionStart);
}
else {
this.setSelectionStart(newSelectionStart);
this.setSelectionEnd(this.__selectionStartOnMouseDown);
}
});
},
/**
* @private
*/