Skip to content

Commit

Permalink
Merge pull request #2007 from asturur/itext-selection-on-canvas
Browse files Browse the repository at this point in the history
Itext selection on canvas
  • Loading branch information
kangax committed Mar 2, 2015
2 parents 2877af6 + 0e384be commit 51c8cd8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
32 changes: 29 additions & 3 deletions src/mixins/itext_behavior.mixin.js
Expand Up @@ -341,11 +341,15 @@
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) {
return this;
}

this.canvas.renderAll();
this.canvas.fire('text:editing:entered', { target: this });
this.initMouseMoveHandler();
return this;
},

Expand All @@ -358,6 +362,28 @@
}, this);
},

/**
* Initializes "mousemove" event handler
*/
initMouseMoveHandler: function() {
var _this = 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);
}
});
},

/**
* @private
*/
Expand Down
23 changes: 0 additions & 23 deletions src/mixins/itext_click_behavior.mixin.js
Expand Up @@ -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();
},
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 51c8cd8

Please sign in to comment.