Skip to content

Commit

Permalink
#3284 – Application crashes after selecting an attachment point and p…
Browse files Browse the repository at this point in the history
…ressing the right mouse button (#3285)
  • Loading branch information
Nitvex authored Sep 12, 2023
1 parent c147c6a commit bfebe07
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,50 @@ import { useCallback } from 'react';
import assert from 'assert';
import { useAppContext } from 'src/hooks';
import Editor from 'src/script/editor';
import { ItemEventParams } from '../contextMenu.types';
import { ContextMenuShowProps, ItemEventParams } from '../contextMenu.types';
import { editRGroupAttachmentPoint } from 'src/script/editor/tool/apoint.utils';
import { Ketcher } from 'ketcher-core';

const getAtomIdByProps = (
props: ContextMenuShowProps | undefined,
ketcher: Ketcher,
): number => {
const editor = ketcher.editor as Editor;
const restruct = editor.render.ctab;
const atomId = props?.atomIds?.[0];
if (atomId != null) {
return atomId;
}

const attachmentPointId = props?.rgroupAttachmentPoints?.[0];
assert(attachmentPointId != null);
const attachmentPoint =
restruct.molecule.rgroupAttachmentPoints.get(attachmentPointId);
assert(attachmentPoint != null);
return attachmentPoint.atomId;
};

const useRGroupAttachmentPointEdit = () => {
const { getKetcherInstance } = useAppContext();

const handler = useCallback(
({ props }: ItemEventParams) => {
const editor = getKetcherInstance().editor as Editor;
const restruct = editor.render.ctab;
const atomId = props?.atomIds?.[0];
assert(atomId != null);
const ketcher = getKetcherInstance();
const restruct = ketcher.editor.render.ctab;
const atomId = getAtomIdByProps(props, ketcher);
const atom = restruct.molecule.atoms.get(atomId);
assert(atom != null);

editRGroupAttachmentPoint(editor, atom, atomId);
editRGroupAttachmentPoint(ketcher.editor, atom, atomId);
},
[getKetcherInstance],
);

const disabled = useCallback(
({ props }: ItemEventParams) => {
const editor = getKetcherInstance().editor as Editor;
const restruct = editor.render.ctab;
const atomId = props?.atomIds?.[0];
assert(atomId != null);
const ketcher = getKetcherInstance();
const restruct = ketcher.editor.render.ctab;
const atomId = getAtomIdByProps(props, ketcher);
const atom = restruct.molecule.atoms.get(atomId);
assert(atom != null);

Expand Down

0 comments on commit bfebe07

Please sign in to comment.