Skip to content

Commit 2a243ef

Browse files
committed
Select Single Bond Tool: 1
Erase Operation with (Del) when hovering on monomer Erase Operation with (Backspace) when hovering on monomer
1 parent abe5355 commit 2a243ef

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

packages/ketcher-macromolecules/src/EditorEvents.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
***************************************************************************/
16-
import { useCallback, useEffect } from 'react';
16+
import { useCallback, useEffect, useRef } from 'react';
1717
import {
1818
hasAntisenseChains,
1919
selectEditor,
@@ -67,6 +67,7 @@ export const EditorEvents = () => {
6767
selectLastSelectedSelectionMenuItem,
6868
);
6969

70+
const hoveredTargetRef = useRef<BaseMonomer | AmbiguousMonomer | null>(null);
7071
const handleMonomersLibraryUpdate = useCallback(() => {
7172
dispatch(loadMonomerLibrary(editor?.monomersLibrary));
7273
dispatch(loadDefaultPresets(editor?.defaultRnaPresetsLibraryItems));
@@ -351,6 +352,7 @@ export const EditorEvents = () => {
351352

352353
const handleClosePreview = useCallback(() => {
353354
debouncedShowPreview.cancel();
355+
hoveredTargetRef.current = null;
354356
dispatch(showPreview(undefined));
355357
}, [debouncedShowPreview, dispatch]);
356358

@@ -366,6 +368,10 @@ export const EditorEvents = () => {
366368

367369
const onMoveHandler = (e) => {
368370
handleClosePreview();
371+
hoveredTargetRef.current =
372+
e.target?.__data__?.monomer ||
373+
e.target?.__data__?.node?.monomer ||
374+
null;
369375
const isLeftClick = e.buttons === 1;
370376
if (!isLeftClick || !noPreviewTools.includes(activeTool)) {
371377
handleOpenPreview(e);
@@ -402,5 +408,24 @@ export const EditorEvents = () => {
402408
}
403409
}, [hasAtLeastOneAntisense]);
404410

411+
useEffect(() => {
412+
const onKeyDown = (e: KeyboardEvent) => {
413+
if (e.key === '1' && editor?.mode.modeName !== 'sequence-layout-mode') {
414+
dispatch(selectTool('bond-single'));
415+
} else {
416+
if (e.key !== 'Delete' && e.key !== 'Backspace') return;
417+
if (e.ctrlKey || e.metaKey || e.altKey) return;
418+
const monomer = hoveredTargetRef.current;
419+
if (!monomer) return;
420+
421+
monomer.selected = true;
422+
editor?.events.deleteSelectedStructure.dispatch();
423+
}
424+
};
425+
426+
window.addEventListener('keydown', onKeyDown);
427+
return () => window.removeEventListener('keydown', onKeyDown);
428+
}, [editor, dispatch]);
429+
405430
return <></>;
406431
};

0 commit comments

Comments
 (0)