Skip to content

Commit

Permalink
#4533 - After inserting a nucleotide in the Text-editing mode, the cu…
Browse files Browse the repository at this point in the history
…rsor blinks in the wrong place
  • Loading branch information
Guch1g0v committed Dec 18, 2024
1 parent 02a8413 commit 42ef3a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,7 @@ export class SequenceMode extends BaseMode {
const currentSequence = SequenceRenderer.currentChain;

const currentSequenceHasPhosphate =
currentSequence?.lastNonEmptyNode?.monomer?.monomerItem?.props?.Name ===
'Phosphate';
currentSequence?.lastNonEmptyNode?.monomer?.isPhosphate;

let nextCaretPosition =
SequenceRenderer.caretPosition + chainsCollection.length;
Expand All @@ -1050,6 +1049,13 @@ export class SequenceMode extends BaseMode {
nextCaretPosition -= 1;
}

const hasPhosphateAtChainEnd =
chainsCollection?.lastNode?.monomer?.isPhosphate;

if (!SequenceRenderer.isCaretAtChainEnd && hasPhosphateAtChainEnd) {
nextCaretPosition -= 1;
}

const modelChanges = this.insertNewSequenceFragment(chainsCollection);

modelChanges.addOperation(new ReinitializeModeOperation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,4 +945,8 @@ export class SequenceRenderer {
SequenceRenderer.chainsCollection.firstNode instanceof EmptySequenceNode
);
}

public static get isCaretAtChainEnd() {
return SequenceRenderer.currentEdittingNode instanceof EmptySequenceNode;
}
}
5 changes: 5 additions & 0 deletions packages/ketcher-core/src/domain/entities/BaseMonomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import assert from 'assert';
import {
IKetAttachmentPoint,
IKetAttachmentPointType,
KetMonomerClass,
} from 'application/formatters/types/ket';
import { RnaSubChain } from 'domain/entities/monomer-chains/RnaSubChain';
import { ChemSubChain } from 'domain/entities/monomer-chains/ChemSubChain';
Expand Down Expand Up @@ -329,6 +330,10 @@ export abstract class BaseMonomer extends DrawingEntity {
return this.attachmentPointsToBonds[attachmentPointName] !== undefined;
}

public get isPhosphate() {
return this.monomerItem?.props?.MonomerClass === KetMonomerClass.Phosphate;
}

public get usedAttachmentPointsNamesList() {
const list: AttachmentPointName[] = [];

Expand Down

0 comments on commit 42ef3a8

Please sign in to comment.