Skip to content

Commit

Permalink
Backmerge: #2329 – Atom editing via right click menu not applied (#2333
Browse files Browse the repository at this point in the history
…) (#2343)
  • Loading branch information
Nitvex authored Mar 14, 2023
1 parent 2b8e7e6 commit b721f6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/ketcher-react/src/script/editor/tool/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class SelectTool {
const atoms = getSelectedAtoms(selection, molecule)
const changeAtomPromise = editor.event.elementEdit.dispatch(atoms)
updateSelectedAtoms({
selection,
atoms: selection?.atoms || [],
editor,
changeAtomPromise
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function handleAtomPropsDialog({
const changeAtomPromise = editor.event.elementEdit.dispatch(atoms)

updateSelectedAtoms({
selection,
atoms: selection.atoms || [],
editor,
changeAtomPromise
})
Expand Down
15 changes: 11 additions & 4 deletions packages/ketcher-react/src/script/ui/state/modal/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,24 @@ export function updateOnlyChangedProperties(atomId, userChangedAtom, molecule) {
)
}

export function updateSelectedAtoms({ selection, changeAtomPromise, editor }) {
export function updateSelectedAtoms({
atoms,
changeAtomPromise,
editor
}: {
atoms: number[]
editor
changeAtomPromise: Promise<Atom>
}) {
const action = new Action()
const struct = editor.render.ctab
const { molecule } = struct
if (selection?.atoms) {
const selectionAtoms = selection.atoms
if (atoms) {
Promise.resolve(changeAtomPromise)
.then((userChangedAtom) => {
// TODO: deep compare to not produce dummy, e.g.
// atom.label != attrs.label || !atom.atomList.equals(attrs.atomList)
selectionAtoms.forEach((atomId) => {
atoms.forEach((atomId) => {
const atomWithChangedProperties = updateOnlyChangedProperties(
atomId,
userChangedAtom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const useAtomEdit = () => {
const newAtom = editor.event.elementEdit.dispatch(atoms)

updateSelectedAtoms({
selection: { atoms },
atoms: atomIds,
changeAtomPromise: newAtom,
editor
})
Expand Down

0 comments on commit b721f6e

Please sign in to comment.