Skip to content

Commit

Permalink
Backmerge: #3176 – Drawing gets broken after dragging a Functional Gr…
Browse files Browse the repository at this point in the history
…oup onto an atom
  • Loading branch information
Nitvex committed Aug 25, 2023
1 parent a6c778c commit de7b25d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion packages/ketcher-core/src/application/editor/actions/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
***************************************************************************/

import { Atom, Bond, RGroup } from 'domain/entities';
import { Atom, Bond, RGroup, SGroupAttachmentPoint } from 'domain/entities';
import {
AtomAdd,
AtomAttr,
Expand All @@ -38,6 +38,7 @@ import { fromBondStereoUpdate } from './bond';
import { without } from 'lodash/fp';
import ReStruct from 'application/render/restruct/restruct';
import assert from 'assert';
import { SGroupAttachmentPointRemove } from '../operations/sgroup/sgroupAttachmentPoints';

export function fromAtomAddition(restruct, pos, atom) {
atom = Object.assign({}, atom);
Expand Down Expand Up @@ -223,6 +224,22 @@ export function fromAtomMerge(restruct, srcId, dstId) {

if (sgChanged) removeSgroupIfNeeded(action, restruct, [srcId]);

const sgroups = atomGetSGroups(restruct, srcId);
sgroups.forEach((sgroupId: number) => {
const sgroup = restruct.sgroups.get(sgroupId).item;
for (let i = 0; i < sgroup.attachmentPoints.length; ++i) {
if (sgroup.attachmentPoints[i].atomId === srcId) {
action.addOp(
new SGroupAttachmentPointRemove(
sgroupId,
new SGroupAttachmentPoint(srcId, undefined, undefined),
),
);
return;
}
}
});

action.addOp(new AtomDelete(srcId));
const dstAtomNeighbors = restruct.molecule.atomGetNeighbors(dstId);
const bond = restruct.molecule.bonds.get(
Expand Down
4 changes: 2 additions & 2 deletions packages/ketcher-core/src/application/editor/actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export function atomGetDegree(restruct, aid) {
return restruct.atoms.get(aid).a.neighbors.length;
}

export function atomGetSGroups(restruct, aid) {
return Array.from(restruct.atoms.get(aid).a.sgs);
export function atomGetSGroups(restruct, atomId: number): number[] {
return Array.from(restruct.atoms.get(atomId).a.sgs);
}

export function atomGetPos(restruct, id) {
Expand Down

0 comments on commit de7b25d

Please sign in to comment.