From fe5b1a640bc614a87a9404768785429a2dd4372e Mon Sep 17 00:00:00 2001 From: Aliaksei Date: Tue, 22 Aug 2023 12:23:50 +0200 Subject: [PATCH] #3128 - When dragging and dropping a Functional Group onto the structure, numerous errors appear in the console --- packages/ketcher-core/src/domain/entities/sgroup.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/ketcher-core/src/domain/entities/sgroup.ts b/packages/ketcher-core/src/domain/entities/sgroup.ts index ed486aa794..cc12855233 100644 --- a/packages/ketcher-core/src/domain/entities/sgroup.ts +++ b/packages/ketcher-core/src/domain/entities/sgroup.ts @@ -316,9 +316,16 @@ export class SGroup { * WHY? When group is contracted we need to understand the represent atom to calculate position. * It is not always the attachmentPoint!! if no attachment point - use the first atom */ - getContractedPosition(struct: Struct): { atomId: number; position: Vec2 } { - const atomId = this.attachmentPoints[0]?.atomId ?? this.atoms[0]; - const representAtom = struct.atoms.get(atomId); + getContractedPosition(struct: Struct): { + atomId: number; + position: Vec2; + } { + let atomId = this.attachmentPoints[0]?.atomId; + let representAtom = struct.atoms.get(atomId); + if (!representAtom) { + atomId = this.atoms[0]; + representAtom = struct.atoms.get(this.atoms[0]); + } assert(representAtom != null); return { atomId, position: representAtom.pp }; }