Skip to content

Commit

Permalink
#1820 – fixed dragging structure on salt or solvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Dec 7, 2022
1 parent 448a616 commit 397d99e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
24 changes: 24 additions & 0 deletions packages/ketcher-core/src/domain/entities/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ export class SGroup {
return saltsAndSolvents.some(({ name }) => name === moleculeName)
}

static isAtomInSaltOrSolvent(
atomId: number,
sgroupsOnCanvas: SGroup[]
): boolean {
const onlySaltsOrSolvents = sgroupsOnCanvas.filter((sgroup) =>
this.isSaltOrSolvent(sgroup.data.name)
)
return onlySaltsOrSolvents.some(({ atoms }) =>
atoms.some((atomIdInSaltOrSolvent) => atomIdInSaltOrSolvent === atomId)
)
}

static isBondInSaltOrSolvent(
bondId: number,
sgroupsOnCanvas: SGroup[]
): boolean {
const onlySaltsOrSolvents = sgroupsOnCanvas.filter((sgroup) =>
this.isSaltOrSolvent(sgroup.data.name)
)
return onlySaltsOrSolvents.some(({ bonds }) =>
bonds.some((bondIdInSaltOrSolvent) => bondIdInSaltOrSolvent === bondId)
)
}

static filterAtoms(atoms: any, map: any) {
const newAtoms: Array<any> = []
for (let i = 0; i < atoms.length; ++i) {
Expand Down
28 changes: 26 additions & 2 deletions packages/ketcher-react/src/script/editor/tool/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
FunctionalGroup,
fromSimpleObjectResizing,
fromArrowResizing,
ReStruct
ReStruct,
ReSGroup
} from 'ketcher-core'

import LassoHelper from './helper/lasso'
Expand Down Expand Up @@ -375,8 +376,12 @@ class SelectTool {
if (dragCtx && dragCtx.stopTapping) dragCtx.stopTapping()

const possibleSaltOrSolvent = struct.sgroups.get(actualSgroupId)
const isDraggingSaltOrSolventOnStructure = SGroup.isSaltOrSolvent(
possibleSaltOrSolvent?.item.data.name
)
if (
SGroup.isSaltOrSolvent(possibleSaltOrSolvent?.item.data.name) &&
(isDraggingSaltOrSolventOnStructure ||
this.isDraggingStructureOnSaltOrSolvent(dragCtx, struct.sgroups)) &&
dragCtx
) {
preventSaltAndSolventsMerge(struct, dragCtx, editor)
Expand Down Expand Up @@ -586,6 +591,25 @@ class SelectTool {
!event.shiftKey ? sel : selMerge(sel, editor.selection(), false)
)
}

isDraggingStructureOnSaltOrSolvent(dragCtx, sgroups: Map<number, ReSGroup>) {
let isDraggingOnSaltOrSolventAtom
let isDraggingOnSaltOrSolventBond
if (dragCtx?.mergeItems) {
const mergeAtoms = Array.from(dragCtx.mergeItems.atoms.values())
const mergeBonds = Array.from(dragCtx.mergeItems.bonds.values())
const sgroupsOnCanvas = Array.from(sgroups.values()).map(
({ item }) => item
)
isDraggingOnSaltOrSolventAtom = mergeAtoms.some((atomId) =>
SGroup.isAtomInSaltOrSolvent(atomId as number, sgroupsOnCanvas)
)
isDraggingOnSaltOrSolventBond = mergeBonds.some((bondId) =>
SGroup.isBondInSaltOrSolvent(bondId as number, sgroupsOnCanvas)
)
}
return isDraggingOnSaltOrSolventAtom || isDraggingOnSaltOrSolventBond
}
}

function closestToSel(ci) {
Expand Down

0 comments on commit 397d99e

Please sign in to comment.