mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-14 08:43:12 +00:00
Stop text from firing mouse up and mouse down on non left clicks (#3888)
* fix right click mouse up * block mouse up/down for text on non left click * fixes also deactivteAllWithDispatch
This commit is contained in:
parent
7f39959bf0
commit
c7cbb391a2
3 changed files with 45 additions and 16 deletions
|
|
@ -1545,9 +1545,16 @@
|
|||
* @chainable
|
||||
*/
|
||||
deactivateAllWithDispatch: function (e) {
|
||||
var allObjects = this.getObjects(),
|
||||
i = 0,
|
||||
len = allObjects.length,
|
||||
obj;
|
||||
for ( ; i < len; i++) {
|
||||
obj = allObjects[i];
|
||||
obj && obj.set('active', false);
|
||||
}
|
||||
this.discardActiveGroup(e);
|
||||
this.discardActiveObject(e);
|
||||
this.deactivateAll();
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@
|
|||
tl: 7 // nw
|
||||
},
|
||||
addListener = fabric.util.addListener,
|
||||
removeListener = fabric.util.removeListener;
|
||||
removeListener = fabric.util.removeListener,
|
||||
RIGHT_CLICK = 3, MIDDLE_CLICK = 2, LEFT_CLICK = 1;
|
||||
|
||||
function checkClick(e, value) {
|
||||
return 'which' in e ? e.which === value : e.button === value - 1;
|
||||
}
|
||||
|
||||
fabric.util.object.extend(fabric.Canvas.prototype, /** @lends fabric.Canvas.prototype */ {
|
||||
|
||||
|
|
@ -303,15 +308,33 @@
|
|||
* @param {Event} e Event object fired on mouseup
|
||||
*/
|
||||
__onMouseUp: function (e) {
|
||||
var target, searchTarget = true, transform = this._currentTransform,
|
||||
groupSelector = this._groupSelector,
|
||||
isClick = (!groupSelector || (groupSelector.left === 0 && groupSelector.top === 0));
|
||||
|
||||
var target;
|
||||
// if right/middle click just fire events and return
|
||||
// target undefined will make the _handleEvent search the target
|
||||
if (checkClick(e, RIGHT_CLICK)) {
|
||||
if (this.fireRightClick) {
|
||||
this._handleEvent(e, 'up', target, RIGHT_CLICK);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkClick(e, MIDDLE_CLICK)) {
|
||||
if (this.fireMiddleClick) {
|
||||
this._handleEvent(e, 'up', target, MIDDLE_CLICK);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isDrawingMode && this._isCurrentlyDrawing) {
|
||||
this._onMouseUpInDrawingMode(e);
|
||||
return;
|
||||
}
|
||||
|
||||
var searchTarget = true, transform = this._currentTransform,
|
||||
groupSelector = this._groupSelector,
|
||||
isClick = (!groupSelector || (groupSelector.left === 0 && groupSelector.top === 0));
|
||||
|
||||
if (transform) {
|
||||
this._finalizeCurrentTransform();
|
||||
searchTarget = !transform.actionPerformed;
|
||||
|
|
@ -352,15 +375,16 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Handle event firing for target and subtargets
|
||||
* @param {Event} e event from mouse
|
||||
* @param {String} eventType event to fire (up, down or move)
|
||||
* @param {fabric.Object} targetObj receiving event
|
||||
*/
|
||||
_handleEvent: function(e, eventType, targetObj) {
|
||||
_handleEvent: function(e, eventType, targetObj, button) {
|
||||
var target = typeof targetObj === 'undefined' ? this.findTarget(e) : targetObj,
|
||||
targets = this.targets || [],
|
||||
options = { e: e, target: target, subTargets: targets };
|
||||
options = { e: e, target: target, subTargets: targets, button: button || LEFT_CLICK };
|
||||
this.fire('mouse:' + eventType, options);
|
||||
target && target.fire('mouse' + eventType, options);
|
||||
for (var i = 0; i < targets.length; i++) {
|
||||
|
|
@ -466,18 +490,16 @@
|
|||
var target = this.findTarget(e);
|
||||
|
||||
// if right click just fire events
|
||||
var isRightClick = 'which' in e ? e.which === 3 : e.button === 2;
|
||||
if (isRightClick) {
|
||||
if (checkClick(e, RIGHT_CLICK)) {
|
||||
if (this.fireRightClick) {
|
||||
this._handleEvent(e, 'down', target ? target : null);
|
||||
this._handleEvent(e, 'down', target ? target : null, RIGHT_CLICK);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var isMiddleClick = 'which' in e ? e.which === 2 : e.button === 1;
|
||||
if (isMiddleClick) {
|
||||
if (checkClick(e, MIDDLE_CLICK)) {
|
||||
if (this.fireMiddleClick) {
|
||||
this._handleEvent(e, 'down', target ? target : null);
|
||||
this._handleEvent(e, 'down', target ? target : null, MIDDLE_CLICK);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
this.__newClickTime = +new Date();
|
||||
var newPointer = this.canvas.getPointer(options.e);
|
||||
|
||||
if (this.isTripleClick(newPointer)) {
|
||||
if (this.isTripleClick(newPointer, options.e)) {
|
||||
this.fire('tripleclick', options);
|
||||
this._stopEvent(options.e);
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
*/
|
||||
initMousedownHandler: function() {
|
||||
this.on('mousedown', function(options) {
|
||||
if (!this.editable) {
|
||||
if (!this.editable || (options.e.button && options.e.button !== 1)) {
|
||||
return;
|
||||
}
|
||||
var pointer = this.canvas.getPointer(options.e);
|
||||
|
|
@ -121,7 +121,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
initMouseupHandler: function() {
|
||||
this.on('mouseup', function(options) {
|
||||
this.__isMousedown = false;
|
||||
if (!this.editable || this._isObjectMoved(options.e)) {
|
||||
if (!this.editable || this._isObjectMoved(options.e) || (options.e.button && options.e.button !== 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue