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

#661 Stereo-label doesn't update after stereoBond flipping #663

Merged
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
15 changes: 9 additions & 6 deletions packages/ketcher-react/src/script/editor/actions/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ function fromBondFlipping(restruct: ReStruct, id: number): Action {
const bond = restruct.molecule.bonds.get(id)

const action = new Action()
action.addOp(new BondDelete(id))
action.addOp(new BondDelete(id).perform(restruct))

// TODO: find better way to avoid problem with bond.begin = 0
if (Number.isInteger(bond?.end) && Number.isInteger(bond?.begin)) {
action.addOp(new BondAdd(bond?.end, bond?.begin, bond))
action.addOp(new BondAdd(bond?.end, bond?.begin, bond).perform(restruct))
}

// todo: swap atoms stereoLabels and stereoAtoms in fragment

return action.perform(restruct)
return action
}

export function fromBondStereoUpdate(
Expand Down Expand Up @@ -306,15 +306,18 @@ export function bondChangingAction(
bondProps: any
): Action {
const action = new Action()
let newItemId
if (
((bondProps.stereo !== Bond.PATTERN.STEREO.NONE && //
bondProps.type === Bond.PATTERN.TYPE.SINGLE) ||
bond.type === Bond.PATTERN.TYPE.DATIVE) &&
bond.type === bondProps.type &&
bond.stereo === bondProps.stereo
)
// if bondTool is stereo and equal to bond for change
) {
action.mergeWith(fromBondFlipping(restruct, itemID))
newItemId = (action.operations[1] as BondAdd).data.bid
}
// if bondTool is stereo and equal to bond for change

const loop = plainBondTypes.includes(bondProps.type) ? plainBondTypes : null
if (
Expand All @@ -326,7 +329,7 @@ export function bondChangingAction(
// if `Single bond` tool is chosen and bond for change in `plainBondTypes`
bondProps.type = loop[(loop.indexOf(bond.type) + 1) % loop.length]

return fromBondsAttrs(restruct, itemID, bondProps).mergeWith(action)
return fromBondsAttrs(restruct, newItemId, bondProps).mergeWith(action)
}

const plainBondTypes = [
Expand Down