Skip to content

Commit

Permalink
#2267&#1994 - Fix Salts&Solvents to replace zero-degree structures (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuleicul committed May 15, 2023
1 parent 829a44b commit d724fc1
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions packages/ketcher-react/src/script/editor/tool/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class TemplateTool {
const dragCtx = this.dragCtx
const ci = dragCtx.item

if (!ci || this.isSaltOrSolvent) {
if (!ci) {
// ci.type == 'Canvas'
delete dragCtx.item
return
Expand Down Expand Up @@ -261,6 +261,11 @@ class TemplateTool {
return true
}

if (this.isSaltOrSolvent) {
delete this.dragCtx.item
return true
}

const dragCtx = this.dragCtx
const ci = dragCtx.item
let targetPos: Vec2 | null | undefined = null
Expand Down Expand Up @@ -436,20 +441,7 @@ class TemplateTool {
let action, functionalGroupRemoveAction
let pasteItems = null

if (this.isSaltOrSolvent) {
addSaltsAndSolventsOnCanvasWithoutMerge(
restruct,
this.template,
dragCtx,
this.editor
)
this.editor.hover(
this.editor.findItem(event, this.findItems),
null,
event
)
return true
} else if (
if (
ci?.map === 'functionalGroups' &&
FunctionalGroup.isContractedFunctionalGroup(
ci.id,
Expand All @@ -458,9 +450,23 @@ class TemplateTool {
this.isModeFunctionalGroup &&
this.targetGroupsIds.length
) {
functionalGroupRemoveAction = new Action()
const restruct = this.editor.render.ctab
const functionalGroupToReplace = this.struct.sgroups.get(ci.id)!

if (
this.isSaltOrSolvent &&
functionalGroupToReplace.isGroupAttached(this.struct)
) {
addSaltsAndSolventsOnCanvasWithoutMerge(
restruct,
this.template,
dragCtx,
this.editor
)
return true
}

functionalGroupRemoveAction = new Action()
const attachmentAtomId = functionalGroupToReplace.getAttAtomId(
this.struct
)
Expand Down Expand Up @@ -489,8 +495,18 @@ class TemplateTool {
dragCtx.action = action
} else if (ci.map === 'atoms') {
const degree = restruct.atoms.get(ci.id)?.a.neighbors.length
let angle

if (degree && degree >= 1 && this.isSaltOrSolvent) {
addSaltsAndSolventsOnCanvasWithoutMerge(
restruct,
this.template,
dragCtx,
this.editor
)
return true
}

let angle
if (degree && degree > 1) {
// common case
angle = null
Expand Down

0 comments on commit d724fc1

Please sign in to comment.