Skip to content

Commit

Permalink
#1826: do not select a hotkey tool if we are hovering over an atom
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinEpam committed Nov 29, 2022
1 parent 1296bd7 commit 0111473
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/ketcher-react/src/script/ui/state/hotkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0111473

Please sign in to comment.