Skip to content

Commit

Permalink
#4927 - Able to change attachment point label to an atom if it is sel…
Browse files Browse the repository at this point in the history
…ected first - 2.23 (#4967)
  • Loading branch information
Guch1g0v committed Jul 5, 2024
1 parent 43aec07 commit 328feb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 7 additions & 3 deletions packages/ketcher-react/src/script/editor/tool/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeMapOfItemsToSet, Struct } from 'ketcher-core';
import { Atom, mergeMapOfItemsToSet, Struct } from 'ketcher-core';

type Items = {
atoms?: number[];
Expand All @@ -9,12 +9,16 @@ function getGroupIdsFromItemArrays(struct: Struct, items?: Items): number[] {
if (!struct.sgroups.size) return [];

const groupsIds = new Set<number>();

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);
Expand Down

0 comments on commit 328feb8

Please sign in to comment.