diff --git a/packages/ketcher-core/src/application/editor/actions/sgroup.ts b/packages/ketcher-core/src/application/editor/actions/sgroup.ts index 0f1dee22a7..7ccb73516c 100644 --- a/packages/ketcher-core/src/application/editor/actions/sgroup.ts +++ b/packages/ketcher-core/src/application/editor/actions/sgroup.ts @@ -79,7 +79,10 @@ export function setExpandSGroup(restruct, sgid, attrs) { }) const sgroup = restruct.molecule.sgroups.get(sgid) - if (sgroup.firstSgroupAtom) delete sgroup.firstSgroupAtom + if (sgroup.firstSgroupAtom) { + delete sgroup.firstSgroupAtom + delete sgroup.firstSgroupAtomId + } const atoms = SGroup.getAtoms(restruct, sgroup) atoms.forEach((aid) => { diff --git a/packages/ketcher-core/src/application/render/restruct/resgroup.js b/packages/ketcher-core/src/application/render/restruct/resgroup.js index f04b2fe2c9..16cf8fc2ee 100644 --- a/packages/ketcher-core/src/application/render/restruct/resgroup.js +++ b/packages/ketcher-core/src/application/render/restruct/resgroup.js @@ -56,6 +56,7 @@ class ReSGroup extends ReObject { if (FunctionalGroup.isAttachmentPointAtom(aid, remol.molecule)) { sgroup.firstSgroupAtom = remol.molecule.atoms.get(aid) sgroup.functionalGroup = true + sgroup.firstSgroupAtomId = aid } }) } else { @@ -139,10 +140,9 @@ class ReSGroup extends ReObject { sGroupItem.firstSgroupAtom if (sGroupHasFirstAtom) { const firstAtomPosition = sGroupItem.firstSgroupAtom.pp - const [firstAtomId] = sGroupItem.atoms - const reSGroupAtom = render.ctab.atoms.get(firstAtomId) + const reSGroupAtom = render.ctab.atoms.get(sGroupItem.firstSgroupAtomId) const sGroupTextBoundingBox = - reSGroupAtom.visel.boundingBox || reSGroupAtom.visel.oldBoundingBox + reSGroupAtom?.visel.boundingBox || reSGroupAtom?.visel.oldBoundingBox if (sGroupTextBoundingBox) { const { x, y } = Scale.obj2scaled(firstAtomPosition, render.options) const { p0, p1 } = sGroupTextBoundingBox diff --git a/packages/ketcher-core/src/domain/entities/sgroup.ts b/packages/ketcher-core/src/domain/entities/sgroup.ts index f591e7e988..826b84e3c7 100644 --- a/packages/ketcher-core/src/domain/entities/sgroup.ts +++ b/packages/ketcher-core/src/domain/entities/sgroup.ts @@ -81,6 +81,7 @@ export class SGroup { pp: Vec2 | null data: any firstSgroupAtom: any + firstSgroupAtomId: number constructor(type: string) { this.type = type @@ -101,6 +102,7 @@ export class SGroup { this.xBonds = [] this.neiAtoms = [] this.pp = null + this.firstSgroupAtomId = -1 this.data = { mul: 1, // multiplication count for MUL group connectivity: 'ht', // head-to-head, head-to-tail or either-unknown diff --git a/packages/ketcher-react/src/script/ui/views/components/StructEditor/InfoPanel.tsx b/packages/ketcher-react/src/script/ui/views/components/StructEditor/InfoPanel.tsx index 1dfa9cac52..9cb6728c1c 100644 --- a/packages/ketcher-react/src/script/ui/views/components/StructEditor/InfoPanel.tsx +++ b/packages/ketcher-react/src/script/ui/views/components/StructEditor/InfoPanel.tsx @@ -29,10 +29,9 @@ import classes from './InfoPanel.module.less' const HOVER_PANEL_PADDING = 20 function getSGroupFirstAtom(sGroup: SGroup, render: Render): Vec2 { - const { firstSgroupAtom } = sGroup + const { firstSgroupAtom, firstSgroupAtomId } = sGroup if (firstSgroupAtom) return firstSgroupAtom.pp - const [firstAtomId] = sGroup.atoms - return render.ctab.atoms?.get(firstAtomId)?.a.pp || new Vec2(0, 0) + return render.ctab.atoms?.get(firstSgroupAtomId)?.a.pp || new Vec2(0, 0) } function getPanelPosition(