Skip to content

Commit

Permalink
fix(): transferring object between active selections
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Sep 15, 2023
1 parent 6fac998 commit 2ccfbde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/shapes/ActiveSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class ActiveSelection extends Group {
* @returns {boolean} true if object entered group
*/
enterGroup(object: FabricObject, removeParentTransform?: boolean) {
if (object.group) {
const parent = object.getParent(true);
if (parent) {
// save ref to group for later in order to return to it
const parent = object.group;
parent._exitGroup(object);
object.__owningGroup = parent;
}
Expand All @@ -100,7 +100,7 @@ export class ActiveSelection extends Group {
*/
exitGroup(object: FabricObject, removeParentTransform?: boolean) {
this._exitGroup(object, removeParentTransform);
const parent = object.__owningGroup;
const parent = object.getParent(true);
if (parent) {
// return to owning group
parent._enterGroup(object, true);
Expand Down
11 changes: 6 additions & 5 deletions src/shapes/Object/StackedObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ export class StackedObject<
* Returns instance's parent **EXCLUDING** `ActiveSelection`
* @param {boolean} [strict] exclude canvas as well
*/
getParent<T extends boolean>(strict?: T): TAncestor | undefined {
return (
(isActiveSelection(this.group) ? this.__owningGroup : this.group) ||
(strict ? undefined : this.canvas)
);
getParent<
T extends boolean,
R = (T extends true ? Group : TCollection) | undefined
>(strict?: T): R {
return ((isActiveSelection(this.group) ? this.__owningGroup : this.group) ||
(strict ? undefined : this.canvas)) as R;
}

/**
Expand Down

0 comments on commit 2ccfbde

Please sign in to comment.