Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/ketcher-core/src/application/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ export class CoreEditor {
this.events.pasteFromClipboard.add(() => {
this.mode.onPaste();
});

this.events.deleteSelectedStructure.add(() => {
if (this.mode instanceof SequenceMode) {
this.mode.deleteSelection();

return;
}

Expand All @@ -772,6 +772,21 @@ export class CoreEditor {
this.drawingEntitiesManager.selectedEntities.map((entity) => entity[1]),
);
});

this.events.deleteHoveredStructure.add(() => {
if (this.mode instanceof SequenceMode) {
this.mode.deleteSelection();
return;
}

const command = new Command();
const history = new EditorHistory(this);

command.merge(this.drawingEntitiesManager.deleteHoveredEntities());
history.update(command);
this.renderersContainer.update(command);
});

this.events.modifyAminoAcids.add(
({ monomers, modificationType }: ModifyAminoAcidsHandlerParams) => {
this.onModifyAminoAcids(monomers, modificationType);
Expand Down
14 changes: 14 additions & 0 deletions packages/ketcher-core/src/application/editor/editorEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface IEditorEvents {
copySelectedStructure: Subscription;
pasteFromClipboard: Subscription;
deleteSelectedStructure: Subscription;
deleteHoveredStructure: Subscription;
selectEntities: Subscription;
toggleMacromoleculesPropertiesVisibility: Subscription;
modifyAminoAcids: Subscription;
Expand Down Expand Up @@ -139,6 +140,7 @@ export function resetEditorEvents() {
copySelectedStructure: new Subscription(),
pasteFromClipboard: new Subscription(),
deleteSelectedStructure: new Subscription(),
deleteHoveredStructure: new Subscription(),
selectEntities: new Subscription(),
toggleMacromoleculesPropertiesVisibility: new Subscription(),
modifyAminoAcids: new Subscription(),
Expand Down Expand Up @@ -246,13 +248,25 @@ export const hotkeysConfiguration = {
editor.onSelectHistory('redo');
},
},
'single-bond': {
shortcut: '1',
handler: (editor: CoreEditor) => {
editor.events.selectTool.dispatch([
ToolName.bondSingle,
{ toolName: ToolName.bondSingle },
]);
},
},
erase: {
shortcut: ['Delete', 'Backspace'],
handler: (editor: CoreEditor) => {
// TODO create an ability to stop event propagation from mode event handlers to keyboard shortcuts handlers
if (editor.isSequenceEditMode) return;
editor.events.selectTool.dispatch([ToolName.erase]);
editor.events.selectTool.dispatch([ToolName.selectRectangle]);
if (editor.drawingEntitiesManager.hoveredEntities.length > 0) {
editor.events.deleteHoveredStructure.dispatch();
}
},
},
clear: {
Expand Down
3 changes: 2 additions & 1 deletion packages/ketcher-core/src/application/editor/tools/Erase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { BaseRenderer } from 'application/render/renderers/BaseRenderer';
import { BaseTool } from 'application/editor/tools/Tool';
import { BaseSequenceRenderer } from 'application/render/renderers/sequence/BaseSequenceRenderer';
import { SequenceMode } from '../modes';
import { Command } from 'domain/entities';

class EraserTool implements BaseTool {
private readonly history: EditorHistory;
Expand All @@ -29,7 +30,7 @@ class EraserTool implements BaseTool {
!(this.editor.mode instanceof SequenceMode)
) {
const modelChanges =
this.editor.drawingEntitiesManager.deleteSelectedEntities();
this.editor.drawingEntitiesManager.deleteSelectedEntities() as Command;
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type cast 'as Command' is redundant because deleteSelectedEntities() already returns a Command type. Consider removing this cast for cleaner code.

Copilot uses AI. Check for mistakes.
modelChanges.merge(
this.editor.drawingEntitiesManager.recalculateAntisenseChains(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ export class DrawingEntitiesManager {
);
}

public get hoveredEntities() {
return this.allEntities.filter(
([, drawingEntity]) => drawingEntity.hovered,
);
}
Comment on lines +213 to +217
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new hoveredEntities getter lacks documentation. Consider adding a JSDoc comment explaining what constitutes a "hovered" entity and how this state is managed, to help future maintainers understand the hover state tracking.

Copilot uses AI. Check for mistakes.

public get selectedMonomers() {
return this.monomersArray.filter((monomer) => monomer.selected);
}
Expand Down Expand Up @@ -298,6 +304,9 @@ export class DrawingEntitiesManager {
}

public deleteSelectedEntities() {
if (this.hoveredEntities.length !== 0) {
return new Command();
}
const mergedCommand = new Command();
this.selectedEntities.forEach(([, drawingEntity]) => {
const command = this.deleteDrawingEntity(drawingEntity);
Expand All @@ -306,6 +315,15 @@ export class DrawingEntitiesManager {
return mergedCommand;
}

public deleteHoveredEntities() {
const mergedCommand = new Command();
this.hoveredEntities.forEach(([, drawingEntity]) => {
const command = this.deleteDrawingEntity(drawingEntity);
mergedCommand.merge(command);
});
return mergedCommand;
}
Comment on lines +318 to +325
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new deleteHoveredEntities method lacks documentation. Consider adding a JSDoc comment explaining its purpose, behavior, and how it differs from deleteSelectedEntities, especially regarding the hover state interactions.

Copilot uses AI. Check for mistakes.

public deleteAllEntities() {
const mergedCommand = new Command();
this.allEntities.forEach(([, drawingEntity]) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/ketcher-core/src/utilities/keynorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const KeyboardModifiers = {
export const KeyCodePrefixes = {
Key: 'Key',
Digit: 'Digit',
Numpad: 'Numpad',
};

export const CanonicalModifiersOrder = [
Expand All @@ -52,6 +53,9 @@ const normalizeCode = (code: string) => {
if (code.startsWith(KeyCodePrefixes.Digit)) {
return code.slice(5);
}
if (code.startsWith(KeyCodePrefixes.Numpad)) {
return code.slice(6);
}

return code;
};
Expand Down
1 change: 1 addition & 0 deletions packages/ketcher-macromolecules/src/EditorEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export const EditorEvents = () => {

const onMoveHandler = (e) => {
handleClosePreview();

const isLeftClick = e.buttons === 1;
if (!isLeftClick || !noPreviewTools.includes(activeTool)) {
handleOpenPreview(e);
Expand Down
Loading