fix 3906 moved target cancellation up so (#3909)

* moved target cancellation up
* added tests
This commit is contained in:
Andrea Bogazzi 2017-05-06 15:03:07 +02:00 committed by GitHub
parent e8766af559
commit ce996e2ec6
2 changed files with 32 additions and 1 deletions

View file

@ -1101,6 +1101,7 @@
// first check current group (if one exists)
// active group does not check sub targets like normal groups.
// if active group just exits.
this.targets = [];
if (activeGroup && !skipGroup && activeGroup === this._searchPossibleTargets([activeGroup], pointer)) {
this._fireOverOutEvents(activeGroup, e);
return activeGroup;
@ -1120,7 +1121,6 @@
}
}
this.targets = [];
var target = this._searchPossibleTargets(this._objects, pointer);
if (e[this.altSelectionKey] && target && activeTarget && target !== activeTarget) {
target = activeTarget;

View file

@ -435,6 +435,37 @@
canvas.remove(group);
});
test('findTarget with subTargetCheck on activeObject', function() {
var rect = makeRect({ left: 0, top: 0 }),
rect2 = makeRect({ left: 30, top: 30}), target,
group = new fabric.Group([rect, rect2]);
canvas.add(group);
canvas.setActiveObject(group);
group.subTargetCheck = true;
target = canvas.findTarget({
clientX: 9, clientY: 9
});
equal(target, group, 'Should return the group');
equal(canvas.targets[0], rect, 'should return the rect');
target = canvas.findTarget({
clientX: 9, clientY: 9
});
target = canvas.findTarget({
clientX: 9, clientY: 9
});
target = canvas.findTarget({
clientX: 9, clientY: 9
});
equal(canvas.targets.length, 1, 'multiple calls to subtarget should not add more to targets');
canvas.remove(group);
});
test('findTarget with perPixelTargetFind', function() {
ok(typeof canvas.findTarget == 'function');
var triangle = makeTriangle({ left: 0, top: 0 }), target;