in packages/ketcher-react/src/script/editor/tool/select/select.ts [109:206]
mousedown(event: PointerEvent) {
this.isMouseDown = true;
const rnd = this.editor.render;
const ctab = rnd.ctab;
const molecule = ctab.molecule;
const map = getMapsForClosestItem(
this.#lassoHelper.fragment || event.altKey,
);
const ci = this.editor.findItem(event, map, null);
const selected = {
...(ci?.map === 'atoms' && { atoms: [ci.id] }),
...(ci?.map === 'bonds' && { bonds: [ci.id] }),
};
const selectedSgroups = ci
? getGroupIdsFromItemArrays(molecule, selected)
: [];
const newSelected = getNewSelectedItems(this.editor, selectedSgroups);
if (newSelected.atoms?.length || newSelected.bonds?.length) {
this.editor.selection(newSelected);
}
const currentPosition = CoordinateTransformation.pageToModel(
event,
this.editor.render,
);
if (!ci) {
onSelectionStart(event, this.editor, this.#lassoHelper);
return true;
}
if (ci.map === MULTITAIL_ARROW_KEY && ci.ref) {
this.dragCtx = this.multitailArrowMoveTool.mousedown(
event,
ci as MultitailArrowClosestItem,
);
} else if (ci.map === 'rxnArrows' && ci.ref) {
this.dragCtx = this.reactionArrowMoveTool.mousedown(
event,
ci as ReactionArrowClosestItem,
);
} else {
this.dragCtx = {
item: ci,
xy0: currentPosition,
};
}
if (!ci || (ci.map === 'atoms' && !event.ctrlKey)) {
atomLongtapEvent(this, rnd);
}
let sel = closestToSel(ci);
const sgroups = ctab.sgroups.get(ci.id);
const selection = this.editor.selection();
if (ci.map === 'frags') {
const frag = ctab.frags.get(ci.id);
sel = {
atoms: frag.fragGetAtoms(ctab, ci.id),
bonds: frag.fragGetBonds(ctab, ci.id),
};
} else if (
(ci.map === 'sgroups' || ci.map === 'functionalGroups') &&
sgroups
) {
const sgroup = sgroups.item;
sel = {
atoms: SGroup.getAtoms(molecule, sgroup),
bonds: SGroup.getBonds(molecule, sgroup),
};
} else if (ci.map === 'rgroups') {
const rgroup = ctab.rgroups.get(ci.id);
sel = {
atoms: rgroup.getAtoms(rnd),
bonds: rgroup.getBonds(rnd),
};
} else if (ci.map === 'sgroupData') {
if (isSelected(selection, ci)) return true;
}
if (event.shiftKey) {
this.editor.selection(selMerge(sel, selection, true));
} else {
this.editor.selection(null);
this.editor.selection(isSelected(selection, ci) ? selection : sel);
}
this.handleMoveCloseToEdgeOfCanvas();
this.isReadyForCopy = false;
this.isCopied = false;
if (isControlKey(event) && this.dragCtx) {
this.isReadyForCopy = true;
}
return true;
}