Skip to content

Commit

Permalink
safeguard canvas (#4650)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur committed Jan 28, 2018
1 parent 2f19c8c commit 6d0ad48
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/mixins/itext_click_behavior.mixin.js
Expand Up @@ -68,31 +68,39 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
},

/**
* Initializes "mousedown" event handler
* Default event handler for the basic functionalities needed on _mouseDown
* can be overridden to do something different.
* Scope of this implementation is: find the click position, set selectionStart
* find selectionEnd, initialize the drawing of either cursor or selection area
*/
initMousedownHandler: function() {
this.on('mousedown', function(options) {
if (!this.editable || (options.e.button && options.e.button !== 1)) {
return;
}
var pointer = this.canvas.getPointer(options.e);
_mouseDownHandler: function(options) {
if (!this.canvas || !this.editable || (options.e.button && options.e.button !== 1)) {
return;
}
var pointer = this.canvas.getPointer(options.e);

this.__mousedownX = pointer.x;
this.__mousedownY = pointer.y;
this.__isMousedown = true;
this.__mousedownX = pointer.x;
this.__mousedownY = pointer.y;
this.__isMousedown = true;

if (this.selected) {
this.setCursorByClick(options.e);
}
if (this.selected) {
this.setCursorByClick(options.e);
}

if (this.isEditing) {
this.__selectionStartOnMouseDown = this.selectionStart;
if (this.selectionStart === this.selectionEnd) {
this.abortCursorAnimation();
}
this.renderCursorOrSelection();
if (this.isEditing) {
this.__selectionStartOnMouseDown = this.selectionStart;
if (this.selectionStart === this.selectionEnd) {
this.abortCursorAnimation();
}
});
this.renderCursorOrSelection();
}
},

/**
* Initializes "mousedown" event handler
*/
initMousedownHandler: function() {
this.on('mousedown', this._mouseDownHandler);
},

/**
Expand Down

0 comments on commit 6d0ad48

Please sign in to comment.