Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subtargets with preserveObjectStacking true #4297

Merged
merged 3 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@
pointer = this.getPointer(e, ignoreZoom),
activeGroup = this.getActiveGroup(),
activeObject = this.getActiveObject(),
activeTarget;
activeTarget, activeTargetSubs;
// first check current group (if one exists)
// active group does not check sub targets like normal groups.
// if active group just exits.
Expand All @@ -1118,12 +1118,15 @@
}
else {
activeTarget = activeObject;
activeTargetSubs = this.targets;
this.targets = [];
}
}

var target = this._searchPossibleTargets(this._objects, pointer);
if (e[this.altSelectionKey] && target && activeTarget && target !== activeTarget) {
target = activeTarget;
this.targets = activeTargetSubs;
}
this._fireOverOutEvents(target, e);
return target;
Expand Down
31 changes: 31 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,37 @@
canvas.remove(group);
});

test('findTarget with subTargetCheck on activeObject and preserveObjectStacking true', function() {
var rect = makeRect({ left: 0, top: 0 }),
rect2 = makeRect({ left: 30, top: 30}), target,
group = new fabric.Group([rect, rect2]);
canvas.preserveObjectStacking = true;
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;
Expand Down