From a00bf26a78c2113451fa04feb398def2f59999dd Mon Sep 17 00:00:00 2001 From: Ruslan <117785539+Guch1g0v@users.noreply.github.com> Date: Thu, 30 May 2024 02:00:38 +0500 Subject: [PATCH] #4509 - In the Text-editing mode, when inserting a fragment after pressing Ctrl+V twice, the cursor is moved to another row (#4664) --- .../src/application/editor/modes/SequenceMode.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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, ), );