-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
perPixelTargetFind not working in nested group. #5287
Changes from 2 commits
34afb37
02cfb33
5985429
940a9f2
b0b0eb0
f453fd3
cc81ea5
9865efd
4c92474
b7b8a26
1d22391
9bb43a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1158,6 +1158,7 @@ | |
|
||
var ignoreZoom = true, | ||
pointer = this.getPointer(e, ignoreZoom), | ||
globalPointer = pointer, | ||
activeObject = this._activeObject, | ||
aObjects = this.getActiveObjects(), | ||
activeTarget, activeTargetSubs; | ||
|
@@ -1167,15 +1168,17 @@ | |
// if active group just exits. | ||
this.targets = []; | ||
|
||
if (aObjects.length > 1 && !skipGroup && activeObject === this._searchPossibleTargets([activeObject], pointer)) { | ||
if (aObjects.length > 1 && | ||
!skipGroup && | ||
activeObject === this._searchPossibleTargets([activeObject],pointer, globalPointer)) { | ||
return activeObject; | ||
} | ||
// if we hit the corner of an activeObject, let's return that. | ||
if (aObjects.length === 1 && activeObject._findTargetCorner(pointer)) { | ||
return activeObject; | ||
} | ||
if (aObjects.length === 1 && | ||
activeObject === this._searchPossibleTargets([activeObject], pointer)) { | ||
activeObject === this._searchPossibleTargets([activeObject], pointer, globalPointer)) { | ||
if (!this.preserveObjectStacking) { | ||
return activeObject; | ||
} | ||
|
@@ -1185,7 +1188,7 @@ | |
this.targets = []; | ||
} | ||
} | ||
var target = this._searchPossibleTargets(this._objects, pointer); | ||
var target = this._searchPossibleTargets(this._objects, pointer, globalPointer); | ||
if (e[this.altSelectionKey] && target && activeTarget && target !== activeTarget) { | ||
target = activeTarget; | ||
this.targets = activeTargetSubs; | ||
|
@@ -1196,13 +1199,14 @@ | |
/** | ||
* @private | ||
*/ | ||
_checkTarget: function(pointer, obj) { | ||
_checkTarget: function(pointer, obj, globalPointer) { | ||
globalPointer = globalPointer || pointer; | ||
if (obj && | ||
obj.visible && | ||
obj.evented && | ||
this.containsPoint(null, obj, pointer)){ | ||
if ((this.perPixelTargetFind || obj.perPixelTargetFind) && !obj.isEditing) { | ||
var isTransparent = this.isTargetTransparent(obj, pointer.x, pointer.y); | ||
var isTransparent = this.isTargetTransparent(obj, globalPointer.x, globalPointer.y); | ||
if (!isTransparent) { | ||
return true; | ||
} | ||
|
@@ -1216,18 +1220,18 @@ | |
/** | ||
* @private | ||
*/ | ||
_searchPossibleTargets: function(objects, pointer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even if those 2 methods are private, we could still document them
can you complete the JSDOC information for _searchPossibleTargets and checkTarget ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
_searchPossibleTargets: function(objects, pointer, pointerOnCanvas) { | ||
|
||
// Cache all targets where their bounding box contains point. | ||
var target, i = objects.length, normalizedPointer, subTarget; | ||
// Do not check for currently grouped objects, since we check the parent group itself. | ||
// until we call this function specifically to search inside the activeGroup | ||
while (i--) { | ||
if (this._checkTarget(pointer, objects[i])) { | ||
if (this._checkTarget(pointer, objects[i], pointerOnCanvas)) { | ||
target = objects[i]; | ||
if (target.subTargetCheck && target instanceof fabric.Group) { | ||
normalizedPointer = this._normalizePointer(target, pointer); | ||
subTarget = this._searchPossibleTargets(target._objects, normalizedPointer); | ||
subTarget = this._searchPossibleTargets(target._objects, normalizedPointer, pointerOnCanvas); | ||
subTarget && this.targets.push(subTarget); | ||
} | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this check necessary? it looks like that we always pass in globalPointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if someone might call this private method directly.
Should I remove this check or just document this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the method is enough, is a private method.
If someone call it directly is gonna have problems anyway since those methods get changed with no information to devs.
We can put this check in searchPossibleTargets that while being private too, is at least one level up of this.
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That make sense to me.