diff --git a/packages/ketcher-react/src/script/editor/tool/atom.ts b/packages/ketcher-react/src/script/editor/tool/atom.ts index dde9c6c4df..a630b3e4c3 100644 --- a/packages/ketcher-react/src/script/editor/tool/atom.ts +++ b/packages/ketcher-react/src/script/editor/tool/atom.ts @@ -57,9 +57,13 @@ class AtomTool implements Tool { editorSelection && getGroupIdsFromItemArrays(struct.molecule, editorSelection); const sgroups = struct.molecule.functionalGroups; - const atomsInFunctionalGroup = editorSelection.atoms.map((atom) => { - return FunctionalGroup.atomsInFunctionalGroup(sgroups, atom); - }); + const atomsInFunctionalGroup = editorSelection.atoms + .filter((atomId) => { + return !Atom.isSuperatomLeavingGroupAtom(struct.molecule, atomId); + }) + .map((atom) => { + return FunctionalGroup.atomsInFunctionalGroup(sgroups, atom); + }); if (atomsInFunctionalGroup.some((atom) => atom !== null)) { editor.event.removeFG.dispatch({ fgIds: [...selectedSGroupsId] }); this.editor.hoverIcon.hide(); diff --git a/packages/ketcher-react/src/script/editor/tool/helper/getGroupIdsFromItems.ts b/packages/ketcher-react/src/script/editor/tool/helper/getGroupIdsFromItems.ts index 88e58754bb..44ae15f46a 100644 --- a/packages/ketcher-react/src/script/editor/tool/helper/getGroupIdsFromItems.ts +++ b/packages/ketcher-react/src/script/editor/tool/helper/getGroupIdsFromItems.ts @@ -1,4 +1,4 @@ -import { mergeMapOfItemsToSet, Struct } from 'ketcher-core'; +import { Atom, mergeMapOfItemsToSet, Struct } from 'ketcher-core'; type Items = { atoms?: number[]; @@ -9,12 +9,16 @@ function getGroupIdsFromItemArrays(struct: Struct, items?: Items): number[] { if (!struct.sgroups.size) return []; const groupsIds = new Set(); - - items?.atoms?.forEach((atomId) => { - const groupId = struct.getGroupIdFromAtomId(atomId); - if (groupId !== null) groupsIds.add(groupId); - }); - + if (items?.atoms) { + items.atoms + .filter((atomId) => { + return !Atom.isSuperatomLeavingGroupAtom(struct, atomId); + }) + .forEach((atomId) => { + const groupId = struct.getGroupIdFromAtomId(atomId); + if (groupId !== null) groupsIds.add(groupId); + }); + } items?.bonds?.forEach((bondId) => { const groupId = struct.getGroupIdFromBondId(bondId); if (groupId !== null) groupsIds.add(groupId);