From 52e9f9448c3502d9c7605ffea8e3c93f6ca1b79f Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 6 May 2017 13:48:35 +0200 Subject: [PATCH 1/2] moved target cancellation up --- src/canvas.class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index 32420a3ea4f..71c25c5942b 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -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; From a8791b7e2f2615972f1edbd376cc31c02ed40a20 Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 6 May 2017 13:58:30 +0200 Subject: [PATCH 2/2] added tests --- test/unit/canvas.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/unit/canvas.js b/test/unit/canvas.js index c0d5ad52ef5..1c37990a9cf 100644 --- a/test/unit/canvas.js +++ b/test/unit/canvas.js @@ -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;