Skip to content

Commit

Permalink
#6462 - Adding peptide between RNA and - symbol breaks sense/antisens…
Browse files Browse the repository at this point in the history
…e chain (#6485)

#6460 - Troubles with switching to Edit mode if - symbol present in sequence
  • Loading branch information
rrodionov91 authored Feb 11, 2025
1 parent 29ee05f commit 0e7b6ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
29 changes: 24 additions & 5 deletions packages/ketcher-core/src/application/editor/modes/SequenceMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ export class SequenceMode extends BaseMode {
) {
const editor = CoreEditor.provideEditorInstance();

this.isEditMode = true;
this.initialize(false, needToRemoveSelection, false);
if (sequenceItemRenderer) {
SequenceRenderer.setCaretPositionNextToMonomer(
sequenceItemRenderer.node.monomer,
);
}

this.isEditMode = true;
this.initialize(false, needToRemoveSelection, false);
editor.events.toggleSequenceEditMode.dispatch(true);
}

Expand Down Expand Up @@ -385,7 +386,6 @@ export class SequenceMode extends BaseMode {
const eventData = event.target?.__data__ as BaseSequenceItemRenderer;

this.turnOnEditMode(eventData);
SequenceRenderer.moveCaretForward();
}

public mousedown(event: MouseEvent) {
Expand Down Expand Up @@ -414,6 +414,10 @@ export class SequenceMode extends BaseMode {
)?.rootBoundingClientRect;
}

if (!sequenceItemBoundingBox) {
return;
}

const isRightSideOfSequenceItemClicked = sequenceItemBoundingBox
? event.clientX >
sequenceItemBoundingBox.x + sequenceItemBoundingBox.width / 2
Expand Down Expand Up @@ -525,6 +529,7 @@ export class SequenceMode extends BaseMode {

private handlePeptideNodeAddition(
enteredSymbol: string,
currentNode: SubChainNode | BackBoneSequenceNode | undefined,
newNodePosition: Vec2,
) {
if (!peptideNaturalAnalogues.includes(enteredSymbol)) {
Expand All @@ -547,7 +552,17 @@ export class SequenceMode extends BaseMode {

modelChanges.merge(peptideAddCommand);

modelChanges.merge(this.insertNewSequenceFragment(newPeptideNode));
modelChanges.merge(
this.insertNewSequenceFragment(
newPeptideNode,
currentNode instanceof BackBoneSequenceNode
? currentNode.secondConnectedNode
: undefined,
currentNode instanceof BackBoneSequenceNode
? currentNode.firstConnectedNode
: undefined,
),
);

return { modelChanges, node: newPeptideNode };
}
Expand Down Expand Up @@ -2164,7 +2179,11 @@ export class SequenceMode extends BaseMode {
}
}
if (editor.sequenceTypeEnterMode === SequenceType.PEPTIDE) {
return this.handlePeptideNodeAddition(enteredSymbol, newNodePosition);
return this.handlePeptideNodeAddition(
enteredSymbol,
currentSenseNode,
newNodePosition,
);
} else {
return this.handleRnaDnaNodeAddition(
enteredSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class BackBoneSequenceNode {
}

public get monomers(): BaseMonomer[] {
return [];
return [this.monomer];
}

public setRenderer(renderer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class EmptySequenceNode {
}

public get monomers(): BaseMonomer[] {
return [];
return [this.monomer];
}

public setRenderer(renderer) {
Expand Down

0 comments on commit 0e7b6ae

Please sign in to comment.