Skip to content

Commit

Permalink
#4878 – Replace of Linking nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
svvald committed Aug 5, 2024
1 parent 53ddcb4 commit fe6a743
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 36 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 136 additions & 30 deletions packages/ketcher-core/src/application/editor/modes/SequenceMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,28 +1070,78 @@ export class SequenceMode extends BaseMode {
selectionRange[0].nodeIndexOverall - 1,
);

selectionRange.forEach((nodeSelection) => {
if (nodeSelection.node instanceof LinkerSequenceNode) {
editor.events.openConfirmationDialog.dispatch({
confirmationText:
'Symbol @ can represent multiple monomers, all of them are going to be deleted. Do you want to proceed?',
onConfirm: () =>
this.replaceSelectionWithMonomer(
if (
selectionRange.some(
(nodeSelection) => nodeSelection.node instanceof LinkerSequenceNode,
)
) {
editor.events.openConfirmationDialog.dispatch({
confirmationText:
'Symbol @ can represent multiple monomers, all of them are going to be deleted. Do you want to proceed?',
onConfirm: () => {
selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithMonomer(
monomerItem,
nodeSelection,
modelChanges,
previousReplacedNode,
),
});
} else {
);
});

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
},
});
} else if (
selectionRange.some(
(nodeSelection) =>
nodeSelection.node.monomer.sideConnections.length !== 0 &&
Object.values(
nodeSelection.node.monomer.attachmentPointsToBonds,
).reduce((count, ap) => {
if (ap) {
count++;
}
return count;
}, 0) > (monomerItem.attachmentPoints?.length ?? 0),
)
) {
editor.events.openConfirmationDialog.dispatch({
confirmationText:
'Side chain connections will be deleted during replacement. Do you want to proceed?',
onConfirm: () => {
selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithMonomer(
monomerItem,
nodeSelection,
modelChanges,
previousReplacedNode,
);
});

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
},
});
} else {
selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithMonomer(
monomerItem,
nodeSelection,
modelChanges,
previousReplacedNode,
);
}
});
});

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
}
});
} else {
const newNodePosition = this.getNewNodePosition();
Expand All @@ -1107,12 +1157,12 @@ export class SequenceMode extends BaseMode {
modelChanges.merge(
this.insertNewSequenceFragment(newMonomerSequenceNode),
);
}

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
}
}

private replaceSelectionWithPreset(
Expand Down Expand Up @@ -1195,14 +1245,70 @@ export class SequenceMode extends BaseMode {
selectionRange[0].nodeIndexOverall - 1,
);

selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithPreset(
preset,
nodeSelection,
modelChanges,
previousReplacedNode,
);
});
if (
selectionRange.some(
(nodeSelection) => nodeSelection.node instanceof LinkerSequenceNode,
)
) {
editor.events.openConfirmationDialog.dispatch({
confirmationText:
'Symbol @ can represent multiple monomers, all of them are going to be deleted. Do you want to proceed?',
onConfirm: () => {
selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithPreset(
preset,
nodeSelection,
modelChanges,
previousReplacedNode,
);
});

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
},
});
} else if (
selectionRange.some(
(nodeSelection) =>
nodeSelection.node.monomer.sideConnections.length !== 0,
)
) {
editor.events.openConfirmationDialog.dispatch({
confirmationText:
'Side chain connections will be deleted during replacement. Do you want to proceed?',
onConfirm: () => {
selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithPreset(
preset,
nodeSelection,
modelChanges,
previousReplacedNode,
);
});

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
},
});
} else {
selectionRange.forEach((nodeSelection) => {
previousReplacedNode = this.replaceSelectionWithPreset(
preset,
nodeSelection,
modelChanges,
previousReplacedNode,
);
});

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
}
});
} else {
const newNodePosition = this.getNewNodePosition();
Expand Down Expand Up @@ -1246,12 +1352,12 @@ export class SequenceMode extends BaseMode {
}

modelChanges.merge(this.insertNewSequenceFragment(newPresetNode));
}

modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
modelChanges.addOperation(new ReinitializeModeOperation());
editor.renderersContainer.update(modelChanges);
SequenceRenderer.moveCaretForward();
history.update(modelChanges);
}
}

private insertNewSequenceItem(editor: CoreEditor, enteredSymbol: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ const COPY = '_Copy';
const MonomerLibrary = () => {
const presetsRef = useRef<IRnaPreset[]>([]);
const dispatch = useAppDispatch();
// const layoutMode = useLayoutMode();
// const isSequenceEditInRNABuilderMode = props?.isSequenceEditInRNABuilderMode;
// const isSequenceMode = layoutMode === 'sequence-layout-mode';
// const isDisabledTabs = isSequenceMode;
// const isDisabledTabsPanels =
// isSequenceMode && !isSequenceEditInRNABuilderMode;

useEffect(() => {
dispatch(setSearchFilter(''));
Expand Down

0 comments on commit fe6a743

Please sign in to comment.