Skip to content

Commit

Permalink
Added isClick boolean to mouseUp events on left click (#3898)
Browse files Browse the repository at this point in the history
* added test

* removed useless method
  • Loading branch information
asturur committed Apr 29, 2017
1 parent 9ce4da2 commit a4ad919
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,34 +357,31 @@
if (target) {
target.isMoving = false;
}

this._handleCursorAndEvent(e, target, 'up');
this._setCursorFromEvent(e, target);
this._handleEvent(e, 'up', target ? target : null, LEFT_CLICK, isClick);
target && (target.__corner = 0);
shouldRender && this.renderAll();
},

/**
* set cursor for mouse up and handle mouseUp event
* @param {Event} e event from mouse
* @param {fabric.Object} target receiving event
* @param {String} eventType event to fire (up, down or move)
*/
_handleCursorAndEvent: function(e, target, eventType) {
this._setCursorFromEvent(e, target);
this._handleEvent(e, eventType, target ? target : null);
},

/**
* @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
* @param {Number} [button] button used in the event 1 = left, 2 = middle, 3 = right
* @param {Boolean} isClick for left button only, indicates that the mouse up happened without move.
*/
_handleEvent: function(e, eventType, targetObj, button) {
_handleEvent: function(e, eventType, targetObj, button, isClick) {
var target = typeof targetObj === 'undefined' ? this.findTarget(e) : targetObj,
targets = this.targets || [],
options = { e: e, target: target, subTargets: targets, button: button || LEFT_CLICK };
options = {
e: e,
target: target,
subTargets: targets,
button: button || LEFT_CLICK,
isClick: isClick || false
};
this.fire('mouse:' + eventType, options);
target && target.fire('mouse' + eventType, options);
for (var i = 0; i < targets.length; i++) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,4 +1769,28 @@
deepEqual(canvas._groupSelector, expectedGroupSelector, 'with object non selectable groupSelector is started');
canvas.__onMouseUp(e);
});

test('mouse:down and group selector isClick = true', function() {
var e = { clientX: 30, clientY: 30, which: 1 };
var isClick = false;
canvas.on('mouse:up', function(opt) {
isClick = opt.isClick;
});
canvas.__onMouseDown(e);
canvas.__onMouseUp(e);
equal(isClick, true, 'without moving the pointer, the click is true');
});

test('mouse:down and group selector isClick = false', function() {
var e = { clientX: 30, clientY: 30, which: 1 };
var e2 = { clientX: 31, clientY: 31, which: 1 };
var isClick = true;
canvas.on('mouse:up', function(opt) {
isClick = opt.isClick;
});
canvas.__onMouseDown(e);
canvas.__onMouseMove(e2);
canvas.__onMouseUp(e2);
equal(isClick, false, 'moving the pointer, the click is false');
});
})();

0 comments on commit a4ad919

Please sign in to comment.