Skip to content

Commit

Permalink
#4726 - Delete of nucleoside symbol turns another nucleoside to nucle…
Browse files Browse the repository at this point in the history
…otide

- skip phosphate add/delete logic for middle/beginning of chain
  • Loading branch information
rrodionov91 committed Jun 6, 2024
1 parent 024c6c1 commit bc22818
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions packages/ketcher-core/src/application/editor/modes/SequenceMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,24 +430,26 @@ export class SequenceMode extends BaseMode {
}

private connectNodes(
node: SubChainNode | undefined,
nextNode: SubChainNode | undefined,
firstNodeToConnect: SubChainNode | undefined,
secondNodeToConnect: SubChainNode | undefined,
modelChanges: Command,
newNodePosition: Vec2,
nextNodeInSameChain?: SubChainNode,
) {
if (
!node ||
node instanceof EmptySequenceNode ||
!nextNode ||
nextNode instanceof EmptySequenceNode
!firstNodeToConnect ||
firstNodeToConnect instanceof EmptySequenceNode ||
!secondNodeToConnect ||
secondNodeToConnect instanceof EmptySequenceNode
) {
return;
}

const editor = CoreEditor.provideEditorInstance();
const nodeR2Bond = node.lastMonomerInNode.attachmentPointsToBonds?.R2;
const nodeR2Bond =
firstNodeToConnect.lastMonomerInNode.attachmentPointsToBonds?.R2;
const nextNodeR1Bond =
nextNode?.firstMonomerInNode?.attachmentPointsToBonds.R1;
secondNodeToConnect?.firstMonomerInNode?.attachmentPointsToBonds.R1;

if (nodeR2Bond || nextNodeR1Bond) {
editor.events.error.dispatch(
Expand All @@ -458,21 +460,23 @@ export class SequenceMode extends BaseMode {
}

if (
node instanceof Nucleoside &&
(nextNode instanceof Nucleotide || nextNode instanceof Nucleoside)
nextNodeInSameChain instanceof EmptySequenceNode &&
firstNodeToConnect instanceof Nucleoside &&
(secondNodeToConnect instanceof Nucleotide ||
secondNodeToConnect instanceof Nucleoside)
) {
modelChanges.merge(
this.bondNodesThroughNewPhosphate(
newNodePosition,
node.lastMonomerInNode,
nextNode.firstMonomerInNode,
firstNodeToConnect.lastMonomerInNode,
secondNodeToConnect.firstMonomerInNode,
),
);
} else {
modelChanges.merge(
editor.drawingEntitiesManager.createPolymerBond(
node.lastMonomerInNode,
nextNode.firstMonomerInNode,
firstNodeToConnect.lastMonomerInNode,
secondNodeToConnect.firstMonomerInNode,
AttachmentPointName.R2,
AttachmentPointName.R1,
),
Expand Down Expand Up @@ -576,8 +580,7 @@ export class SequenceMode extends BaseMode {

if (
nodeBeforeSelection instanceof Nucleoside &&
(nodeAfterSelection instanceof Nucleotide ||
nodeAfterSelection instanceof Nucleoside)
nodeAfterSelection instanceof Nucleotide
) {
modelChanges.merge(
this.bondNodesThroughNewPhosphate(
Expand Down Expand Up @@ -972,6 +975,7 @@ export class SequenceMode extends BaseMode {
firstNodeOfNewFragment,
modelChanges,
newNodePosition,
currentNode,
);

this.connectNodes(
Expand Down

0 comments on commit bc22818

Please sign in to comment.