Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4927 - Able to change attachment point label to an atom if it is selected first #4967

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading