diff --git a/packages/ketcher-core/src/application/editor/actions/sgroup.ts b/packages/ketcher-core/src/application/editor/actions/sgroup.ts index 21965f2ada..0f1dee22a7 100644 --- a/packages/ketcher-core/src/application/editor/actions/sgroup.ts +++ b/packages/ketcher-core/src/application/editor/actions/sgroup.ts @@ -24,7 +24,7 @@ import { SGroupDelete, SGroupRemoveFromHierarchy } from '../operations' -import { Pile, SGroup } from 'domain/entities' +import { FunctionalGroup, Pile, SGroup } from 'domain/entities' import { atomGetAttr, atomGetDegree, atomGetSGroups } from './utils' import { Action } from './action' @@ -91,6 +91,29 @@ export function setExpandSGroup(restruct, sgid, attrs) { return action.perform(restruct) } +// todo delete after supporting expand - collapse for 2 attachment points +export function expandSGroupWithMultipleAttachmentPoint(restruct) { + const action = new Action() + + const struct = restruct.molecule + + struct.sgroups.forEach((sgroup) => { + const countAttachmentPoint = FunctionalGroup.getAttachmentPointCount( + sgroup, + struct + ) + if (countAttachmentPoint > 1) { + action.mergeWith( + setExpandSGroup(restruct, sgroup.id, { + expanded: true + }) + ) + } + }) + + return action +} + export function sGroupAttributeAction(id, attrs) { const action = new Action() diff --git a/packages/ketcher-react/src/script/editor/tool/paste.ts b/packages/ketcher-react/src/script/editor/tool/paste.ts index 9c46be9e74..c1261d55c6 100644 --- a/packages/ketcher-react/src/script/editor/tool/paste.ts +++ b/packages/ketcher-react/src/script/editor/tool/paste.ts @@ -15,13 +15,13 @@ ***************************************************************************/ import { + expandSGroupWithMultipleAttachmentPoint, fromItemsFuse, fromPaste, fromTemplateOnAtom, FunctionalGroup, getHoverToFuse, getItemsToFuse, - setExpandSGroup, SGroup, Struct, Vec2 @@ -62,20 +62,10 @@ class PasteTool { this.action = action this.editor.update(this.action, true) - // todo delete after supporting expand - collapse for 2 attachment points - struct.sgroups.forEach((sgroup) => { - const countAttachmentPoint = FunctionalGroup.getAttachmentPointCount( - sgroup, - this.editor.render.ctab.molecule - ) - if (countAttachmentPoint > 1) { - action.mergeWith( - setExpandSGroup(this.editor.render.ctab, sgroup.id, { - expanded: true - }) - ) - } - }) + action.mergeWith( + expandSGroupWithMultipleAttachmentPoint(this.editor.render.ctab) + ) + this.editor.update(this.action, true) this.findItems = ['functionalGroups'] diff --git a/packages/ketcher-react/src/script/editor/tool/sgroup.ts b/packages/ketcher-react/src/script/editor/tool/sgroup.ts index 4d6960f431..82568c7a5d 100644 --- a/packages/ketcher-react/src/script/editor/tool/sgroup.ts +++ b/packages/ketcher-react/src/script/editor/tool/sgroup.ts @@ -23,7 +23,8 @@ import { fromSgroupDeletion, FunctionalGroup, SGroup, - Pool + Pool, + expandSGroupWithMultipleAttachmentPoint } from 'ketcher-core' import LassoHelper from './helper/lasso' @@ -512,6 +513,8 @@ class SGroupTool { newSg.attrs ).mergeWith(fromSgroupDeletion(restruct, id)) + action.mergeWith(expandSGroupWithMultipleAttachmentPoint(restruct)) + editor.update(action) editor.selection(selection) return