diff --git a/src/mixins/itext_click_behavior.mixin.js b/src/mixins/itext_click_behavior.mixin.js index cad56c43338..dce14704305 100644 --- a/src/mixins/itext_click_behavior.mixin.js +++ b/src/mixins/itext_click_behavior.mixin.js @@ -15,12 +15,17 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot this.on('mousedown', this.onMouseDown.bind(this)); }, + /** + * Default event handler to simulate triple click + * @private + */ onMouseDown: function(options) { - + if (!this.canvas) { + return; + } this.__newClickTime = +new Date(); var newPointer = this.canvas.getPointer(options.e); - - if (this.isTripleClick(newPointer, options.e)) { + if (this.isTripleClick(newPointer)) { this.fire('tripleclick', options); this._stopEvent(options.e); } @@ -104,6 +109,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot }, /** + * detect if object moved * @private */ _isObjectMoved: function(e) { @@ -117,23 +123,29 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot * Initializes "mouseup" event handler */ initMouseupHandler: function() { - this.on('mouseup', function(options) { - this.__isMousedown = false; - if (!this.editable || this._isObjectMoved(options.e) || (options.e.button && options.e.button !== 1)) { - return; - } + this.on('mouseup', this.mouseUpHandler); + }, - if (this.__lastSelected && !this.__corner) { - this.enterEditing(options.e); - if (this.selectionStart === this.selectionEnd) { - this.initDelayedCursor(true); - } - else { - this.renderCursorOrSelection(); - } + /** + * standard hander for mouse up, overridable + * @private + */ + mouseUpHandler: function(options) { + this.__isMousedown = false; + if (!this.editable || this._isObjectMoved(options.e) || (options.e.button && options.e.button !== 1)) { + return; + } + + if (this.__lastSelected && !this.__corner) { + this.enterEditing(options.e); + if (this.selectionStart === this.selectionEnd) { + this.initDelayedCursor(true); } - this.selected = true; - }); + else { + this.renderCursorOrSelection(); + } + } + this.selected = true; }, /**