From 0111473c0ab0028150d5203f307fb4fa0cee3519 Mon Sep 17 00:00:00 2001 From: Konstantin Levin Date: Tue, 29 Nov 2022 18:27:14 +0100 Subject: [PATCH] #1826: do not select a hotkey tool if we are hovering over an atom --- .../src/script/ui/state/hotkeys.js | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/ketcher-react/src/script/ui/state/hotkeys.js b/packages/ketcher-react/src/script/ui/state/hotkeys.js index b7d0fd64eb..7a5b5295e0 100644 --- a/packages/ketcher-react/src/script/ui/state/hotkeys.js +++ b/packages/ketcher-react/src/script/ui/state/hotkeys.js @@ -20,7 +20,8 @@ import { KetSerializer, MolSerializer, formatProperties, - ChemicalMimeType + ChemicalMimeType, + fromAtomsAttrs } from 'ketcher-core' import { debounce, isEqual } from 'lodash/fp' import { load, onAction } from './shared' @@ -42,7 +43,8 @@ export function initKeydownListener(element) { function keyHandle(dispatch, state, hotKeys, event) { if (state.modal) return - const editor = state.editor + const { editor } = state + const { render } = editor const actionState = state.actionState const actionTool = actionState.activeTool @@ -69,7 +71,19 @@ function keyHandle(dispatch, state, hotKeys, event) { } if (clipArea.actions.indexOf(actName) === -1) { const newAction = actions[actName].action - dispatch(onAction(newAction)) + const hoverItemId = getHoveredAtomId(render.ctab.atoms) + const isHoveringOverAtom = hoverItemId !== null + if (isHoveringOverAtom) { + // check if atom is currently hovered over + // in this case we do not want to activate the corresponding tool + // and just insert the atom directly + const atomProps = { ...newAction.opts } + const updatedAtoms = fromAtomsAttrs(render.ctab, hoverItemId, atomProps, true) + editor.update(updatedAtoms) + } else { + dispatch(onAction(newAction)) + } + event.preventDefault() } else if (window.clipboardData) { // IE support @@ -78,6 +92,13 @@ function keyHandle(dispatch, state, hotKeys, event) { } } +function getHoveredAtomId(atoms) { + for (let [id, atom] of atoms.entries()) { + if (atom.hover) return id + } + return null +} + function setHotKey(key, actName, hotKeys) { if (Array.isArray(hotKeys[key])) hotKeys[key].push(actName) else hotKeys[key] = [actName] @@ -172,7 +193,7 @@ function clipData(editor) { if (simpleObjectOrText && window.clipboardData) { errorHandler( 'The structure you are trying to copy contains Simple object or/and Text object.' + - 'To copy Simple object or Text object in Internet Explorer try "Copy as KET" button' + 'To copy Simple object or Text object in Internet Explorer try "Copy as KET" button' ) return null }