diff --git a/packages/ketcher-core/src/application/editor/actions/bond.ts b/packages/ketcher-core/src/application/editor/actions/bond.ts index 3dec2bd0a2..04858b77e5 100644 --- a/packages/ketcher-core/src/application/editor/actions/bond.ts +++ b/packages/ketcher-core/src/application/editor/actions/bond.ts @@ -67,7 +67,7 @@ export function fromBondAddition( action.addOp(new FragmentAdd().perform(reStruct)) as FragmentAdd ).frid - const newBeginAtomId = ( + const newBeginAtomId: number = ( action.addOp( new AtomAdd( { ...beginAtomAttr, fragment: newFragmentId }, @@ -76,7 +76,7 @@ export function fromBondAddition( ) as AtomAdd ).data.aid - const newEndAtomId = ( + const newEndAtomId: number = ( action.addOp( new AtomAdd( { ...endAtomAttr, fragment: newFragmentId }, @@ -94,7 +94,7 @@ export function fromBondAddition( ) => { const fragmentId = atomGetAttr(reStruct, endAtomId, 'fragment') - const newBeginAtomId = ( + const newBeginAtomId: number = ( action.addOp( new AtomAdd( { ...beginAtomAttr, fragment: fragmentId }, @@ -122,7 +122,7 @@ export function fromBondAddition( ) => { const fragmentId = atomGetAttr(reStruct, beginAtomId, 'fragment') - const newEndAtomId = ( + const newEndAtomId: number = ( action.addOp( new AtomAdd( { diff --git a/packages/ketcher-core/src/domain/entities/sgroup.ts b/packages/ketcher-core/src/domain/entities/sgroup.ts index 9c874b7327..f591e7e988 100644 --- a/packages/ketcher-core/src/domain/entities/sgroup.ts +++ b/packages/ketcher-core/src/domain/entities/sgroup.ts @@ -651,6 +651,9 @@ export class SGroup { return !expanded && isSGroup } + /** + * @returns `undefined`: if it's salt or solvent + */ static getAttachmentAtomIdBySGroupId(sGroupId: number, struct: Struct) { const functionalGroup = struct.functionalGroups.get(sGroupId) if (!SGroup.isSaltOrSolvent(functionalGroup?.name || '')) { diff --git a/packages/ketcher-react/src/script/editor/tool/bond.ts b/packages/ketcher-react/src/script/editor/tool/bond.ts index 2e8a8415ca..fc86a1137b 100644 --- a/packages/ketcher-react/src/script/editor/tool/bond.ts +++ b/packages/ketcher-react/src/script/editor/tool/bond.ts @@ -168,10 +168,10 @@ class BondTool { ) { const closestAttachmentAtomId = SGroup.getAttachmentAtomIdBySGroupId(closestSGroup.id, molecule) - if ( - closestAttachmentAtomId && - closestAttachmentAtomId !== beginAtom - ) { + const isSaltOrSolvent = closestAttachmentAtomId === undefined + const isBeginFunctionalGroupItself = + closestAttachmentAtomId === beginAtom + if (!isSaltOrSolvent && !isBeginFunctionalGroupItself) { endAtom = { id: closestAttachmentAtomId, map: 'atoms'