From 2ccfbde30eafa955c3d3366dbe3c41516f256381 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Fri, 15 Sep 2023 14:25:25 +0530 Subject: [PATCH] fix(): transferring object between active selections --- src/shapes/ActiveSelection.ts | 6 +++--- src/shapes/Object/StackedObject.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/shapes/ActiveSelection.ts b/src/shapes/ActiveSelection.ts index 71bc0eadabe..f72f361af8b 100644 --- a/src/shapes/ActiveSelection.ts +++ b/src/shapes/ActiveSelection.ts @@ -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; } @@ -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); diff --git a/src/shapes/Object/StackedObject.ts b/src/shapes/Object/StackedObject.ts index ca7876a1891..fbde7fb1d0e 100644 --- a/src/shapes/Object/StackedObject.ts +++ b/src/shapes/Object/StackedObject.ts @@ -48,11 +48,12 @@ export class StackedObject< * Returns instance's parent **EXCLUDING** `ActiveSelection` * @param {boolean} [strict] exclude canvas as well */ - getParent(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; } /**