Skip to content

Commit

Permalink
#4773 - It is impossible to apply R-group to atom with attachment poi…
Browse files Browse the repository at this point in the history
…nt attached (#4855)

* #4773 - It is impossible to apply R-group to atom with attachment point attached

* hotfix: add logic for charge tool
  • Loading branch information
Guch1g0v authored Jun 21, 2024
1 parent 0173cf1 commit 7ab4107
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
15 changes: 12 additions & 3 deletions packages/ketcher-react/src/script/editor/tool/apoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
***************************************************************************/

import assert from 'assert';
import { FunctionalGroup } from 'ketcher-core';
import { Atom, FunctionalGroup } from 'ketcher-core';
import Editor from '../Editor';
import { Tool } from './Tool';
import { editRGroupAttachmentPoint } from './apoint.utils';
Expand Down Expand Up @@ -60,6 +60,13 @@ class APointTool implements Tool {
functionalGroups,
ci.id,
);
const isAtomSuperatomLeavingGroup = Atom.isSuperatomLeavingGroupAtom(
molecule,
ci.id,
);
if (isAtomSuperatomLeavingGroup) {
return;
}

if (atomId !== null) {
atomResult.push(atomId);
Expand All @@ -76,8 +83,10 @@ class APointTool implements Tool {
result.push(fgId);
}
}
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
if (result.length > 0) {
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
}
}

if (ci && ci.map === 'atoms') {
Expand Down
15 changes: 12 additions & 3 deletions packages/ketcher-react/src/script/editor/tool/charge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
***************************************************************************/

import { Elements, fromAtomsAttrs, FunctionalGroup } from 'ketcher-core';
import { Atom, Elements, fromAtomsAttrs, FunctionalGroup } from 'ketcher-core';
import Editor from '../Editor';
import { Tool } from './Tool';

Expand Down Expand Up @@ -59,6 +59,13 @@ class ChargeTool implements Tool {
functionalGroups,
ci.id,
);
const isAtomSuperatomLeavingGroup = Atom.isSuperatomLeavingGroupAtom(
molecule,
ci.id,
);
if (isAtomSuperatomLeavingGroup) {
return;
}

if (atomId !== null) {
atomResult.push(atomId);
Expand All @@ -76,8 +83,10 @@ class ChargeTool implements Tool {
result.push(fgId);
}
}
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
if (result.length > 0) {
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
}
}

if (
Expand Down
14 changes: 11 additions & 3 deletions packages/ketcher-react/src/script/editor/tool/rgroupatom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ class RGroupAtomTool implements Tool {
functionalGroups,
ci.id,
);

const isAtomSuperatomLeavingGroup = Atom.isSuperatomLeavingGroupAtom(
molecule,
ci.id,
);
if (isAtomSuperatomLeavingGroup) {
return;
}
if (atomId !== null) {
atomResult.push(atomId);
}
Expand All @@ -78,8 +84,10 @@ class RGroupAtomTool implements Tool {
result.push(fgId);
}
}
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
if (result.length > 0) {
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
}
}

if (!ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class RGroupFragmentTool implements Tool {
result.push(fgId);
}
}
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
if (result.length > 0) {
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
}
} else if (bondResult.length > 0) {
for (const id of bondResult) {
const fgId = FunctionalGroup.findFunctionalGroupByBond(
Expand Down
7 changes: 4 additions & 3 deletions packages/ketcher-react/src/script/editor/tool/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ class SGroupTool implements Tool {
result.push(fgId);
}
}

this.editor.event.removeFG.dispatch({ fgIds: result });
return;
if (result.length > 0) {
this.editor.event.removeFG.dispatch({ fgIds: result });
return;
}
} else if (bondResult.length > 0) {
for (const id of bondResult) {
const fgId = FunctionalGroup.findFunctionalGroupByBond(
Expand Down

0 comments on commit 7ab4107

Please sign in to comment.