diff --git a/packages/ketcher-core/src/application/editor/modes/SequenceMode.ts b/packages/ketcher-core/src/application/editor/modes/SequenceMode.ts index a3ac92f04f..9fc58077c6 100644 --- a/packages/ketcher-core/src/application/editor/modes/SequenceMode.ts +++ b/packages/ketcher-core/src/application/editor/modes/SequenceMode.ts @@ -835,6 +835,20 @@ export class SequenceMode extends BaseMode { const chainsCollection = ChainsCollection.fromMonomers([ ...drawingEntitiesManager.monomers.values(), ]); + + const currentSequence = SequenceRenderer.currentChain; + + const currentSequenceHasPhosphate = + currentSequence?.lastNonEmptyNode?.monomer?.monomerItem?.props?.Name === + 'Phosphate'; + + let nextCaretPosition = + SequenceRenderer.caretPosition + chainsCollection.length; + + if (currentSequenceHasPhosphate) { + nextCaretPosition -= 1; + } + const modelChanges = this.insertNewSequenceFragment(chainsCollection); modelChanges.addOperation(new ReinitializeModeOperation()); @@ -842,7 +856,7 @@ export class SequenceMode extends BaseMode { modelChanges.addOperation( new RestoreSequenceCaretPositionOperation( SequenceRenderer.caretPosition, - SequenceRenderer.caretPosition + chainsCollection.length, + nextCaretPosition, ), );