Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Mar 1, 2018
1 parent 2efa3c8 commit 8a6686a
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/mixins/itext_click_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -104,6 +109,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
},

/**
* detect if object moved
* @private
*/
_isObjectMoved: function(e) {
Expand All @@ -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;
},

/**
Expand Down

0 comments on commit 8a6686a

Please sign in to comment.