From bb5239ad5178e91df814ecd4682b20420ca06d0d Mon Sep 17 00:00:00 2001 From: Roman Rodionov Date: Mon, 13 May 2024 11:11:41 +0200 Subject: [PATCH] #4548 - Cyclic chains disappear from canvas when try to Edit in the sequence mode (#4609) - used lastNonEmptyNode instead of lastNode for cyclic chain end bond render Co-authored-by: Dmitry Baranov --- .../renderers/sequence/SequenceRenderer.ts | 2 +- .../domain/entities/monomer-chains/Chain.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/ketcher-core/src/application/render/renderers/sequence/SequenceRenderer.ts b/packages/ketcher-core/src/application/render/renderers/sequence/SequenceRenderer.ts index 58c0ef56a7..e8d3fbadb9 100644 --- a/packages/ketcher-core/src/application/render/renderers/sequence/SequenceRenderer.ts +++ b/packages/ketcher-core/src/application/render/renderers/sequence/SequenceRenderer.ts @@ -218,7 +218,7 @@ export class SequenceRenderer { const bondRenderer = new PolymerBondSequenceRenderer( polymerBond, chain.firstNode, - chain.lastNode, + chain.lastNonEmptyNode, ); bondRenderer.show(); polymerBond.setRenderer(bondRenderer); diff --git a/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts b/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts index 143490ba5a..8058ccae23 100644 --- a/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts +++ b/packages/ketcher-core/src/domain/entities/monomer-chains/Chain.ts @@ -95,10 +95,29 @@ export class Chain { return this.subChains[this.subChains.length - 1]; } + public get nodes() { + const nodes: SubChainNode[] = []; + this.subChains.forEach((subChain) => { + nodes.push(...subChain.nodes); + }); + + return nodes; + } + public get lastNode() { return this.lastSubChain?.lastNode; } + public get lastNonEmptyNode() { + if (this.lastNode instanceof EmptySequenceNode) { + const nodes = this.nodes; + + return nodes[nodes.length - 2]; + } else { + return this.lastNode; + } + } + public get firstSubChain() { return this.subChains[0]; }