Skip to content

Commit

Permalink
Backmerge: #4369 - Del button works as Backspace button that is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
NataliaLoginova authored and burcinkarimov committed Apr 16, 2024
1 parent 609bcd1 commit d761100
Showing 1 changed file with 61 additions and 48 deletions.
109 changes: 61 additions & 48 deletions packages/ketcher-core/src/application/editor/modes/SequenceMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const naturalAnalogues = uniq([
...peptideNaturalAnalogues,
]);

enum Direction {
Left = 'left',
Right = 'right',
}

export class SequenceMode extends BaseMode {
private _isEditMode = false;
private _isEditInRNABuilderMode = false;
Expand Down Expand Up @@ -541,57 +546,65 @@ export class SequenceMode extends BaseMode {
}

get keyboardEventHandlers() {
return {
delete: {
shortcut: ['Backspace', 'Delete'],
handler: () => {
if (!this.isEditMode) {
return;
}
const editor = CoreEditor.provideEditorInstance();
const previousNode = SequenceRenderer.previousNode;
const previousCaretPosition = SequenceRenderer.caretPosition;
const selections = SequenceRenderer.selections;
const modelChanges = new Command();
let nodesToDelete: NodesSelection;

if (selections.length) {
modelChanges.merge(this.deleteSelectedDrawingEntities());
nodesToDelete = selections;
} else if (previousNode) {
previousNode.monomers.forEach((monomer) => {
modelChanges.merge(
editor.drawingEntitiesManager.deleteMonomer(monomer),
);
});
nodesToDelete = [
[
{
node: previousNode,
nodeIndexOverall:
SequenceRenderer.previousCaretPosition as number,
},
],
];
} else {
return;
}
const deleteNode = (direction: Direction) => {
const editor = CoreEditor.provideEditorInstance();
const nodeToDelete =
direction === Direction.Left
? SequenceRenderer.previousNode
: SequenceRenderer.getNodeByPointer(SequenceRenderer.caretPosition);
const caretPosition =
direction === Direction.Left
? (SequenceRenderer.previousCaretPosition as number)
: SequenceRenderer.caretPosition;
const selections = SequenceRenderer.selections;
const modelChanges = new Command();
let nodesToDelete: NodesSelection;

if (selections.length) {
modelChanges.merge(this.deleteSelectedDrawingEntities());
nodesToDelete = selections;
} else if (nodeToDelete) {
nodeToDelete.monomers.forEach((monomer) => {
modelChanges.merge(
editor.drawingEntitiesManager.deleteMonomer(monomer),
);
});
nodesToDelete = [
[
{
node: nodeToDelete,
nodeIndexOverall: caretPosition,
},
],
];
} else {
return;
}

modelChanges.merge(this.handleNodesDeletion(nodesToDelete));
modelChanges.merge(this.handleNodesDeletion(nodesToDelete));

this.finishNodesDeletion(
modelChanges,
previousCaretPosition,
nodesToDelete[0][0].nodeIndexOverall,
);
this.finishNodesDeletion(
modelChanges,
nodesToDelete[0][0].nodeIndexOverall,
nodesToDelete[0][0].nodeIndexOverall,
);

if (
SequenceRenderer.caretPosition === 0 &&
SequenceRenderer.chainsCollection.chains.length === 0
) {
this.startNewSequence();
}
},
if (
SequenceRenderer.caretPosition === 0 &&
SequenceRenderer.chainsCollection.chains.length === 0
) {
this.startNewSequence();
}
};

return {
delete: {
shortcut: ['Delete'],
handler: () => deleteNode(Direction.Right),
},
backspace: {
shortcut: ['Backspace'],
handler: () => deleteNode(Direction.Left),
},
'turn-off-edit-mode': {
shortcut: ['Escape'],
Expand Down

0 comments on commit d761100

Please sign in to comment.